可信度高 传严歌苓获诺贝尔文学奖# Joke - 肚皮舞运动
w*x
1 楼
int myatoi(const char* p)
{
assert(p);
bool bNeg = false;
if ('-' == *p || '+' == *p)
{
bNeg = '-' == *p;
p++;
}
if (*p == 0) throw CException();
//use unsigned to deal with INT_MIN
unsigned int nAbsValue = 0;
while (*p != 0)
{
if (*p < '0' || *p > '9')
throw CException();
unsigned int nOrgValue = nAbsValue;
int nDigit = *p - '0';
nAbsValue = 10*nAbsValue + nDigit;
//deal with normal overflow
if (nAbsValue > INT_MIN || (nAbsValue - nDigit)/10 != nOrgValue)
throw CException();
//deal with 2147483648 (-2147483648 == INT_MIN)
if (!bNeg && nAbsValue == INT_MIN)
throw CException();
p++;
}
return bNeg ? -((int)nAbsValue) : (int)nAbsValue;
}
{
assert(p);
bool bNeg = false;
if ('-' == *p || '+' == *p)
{
bNeg = '-' == *p;
p++;
}
if (*p == 0) throw CException();
//use unsigned to deal with INT_MIN
unsigned int nAbsValue = 0;
while (*p != 0)
{
if (*p < '0' || *p > '9')
throw CException();
unsigned int nOrgValue = nAbsValue;
int nDigit = *p - '0';
nAbsValue = 10*nAbsValue + nDigit;
//deal with normal overflow
if (nAbsValue > INT_MIN || (nAbsValue - nDigit)/10 != nOrgValue)
throw CException();
//deal with 2147483648 (-2147483648 == INT_MIN)
if (!bNeg && nAbsValue == INT_MIN)
throw CException();
p++;
}
return bNeg ? -((int)nAbsValue) : (int)nAbsValue;
}