void itoa(int n,char s[])
{
int i,sign;
unsigned int un; // <===== add unsigned int un
if ((sign=n)<0)
un=(unsigned int)n; // <=== change n to un
i=0;
do
{
s[i++]= un % 10 + '0'; // <=== change n to un
} while ((un /-10)>0); // <=== change n to un
编译警告的实际上并不是语句n = (unsigned int)n;而是语句int i = -2147483648;引起的,这我就更不明白了,如果n = -2147483648,那么前者应该产生“warning:assignment to 'int' from 'unsigned int'”才对,而不是后者有"warning:decimal constant is so large that is unsigned"才对啊。
unsigned int range : 0 to 4294967295
int range : -2147483648 to 2147483647
int n;
n=-2147483648;
n = (unsigned int)n; // <== (unsigned int) n equals +2147483648 (no minus)
// but 左边n is declared int, n = +2147483648 .... exceeds 2147483647 !!!
我是这样理解。
不知道,对不对。。
我是用visual c 2008 没有warning.