编译警告信息
warning: this decimal constant is unsigned only in ISO C90
原因:数字超出默认类型int型的表示范围。
在gcc中缺省使用C90标准编译,编译器将按C90标准将你的-2147483648转成无符号的十进制(但不影响你的结果)。
解决方法:
1:不用管。
2:在该数字后加u
(大小写无关),变为无符号整型(0~4294967295)。
3:在gcc的编译选项中加 --std=c99
。
4:使用十六进制的数字
,如0xFFFFFFFF
The C90 rule that the default type of a decimal integer constant is either int, long, or
unsigned long, depending on which type is large enough to hold the value without overflow,
simplifies the use of constants. The choices in C99 are int, long and long long.
C89 added the suffixes U and u to specify unsigned numbers. C99 adds LL to specify long
long.
Unlike decimal constants, octal and hexadecimal constants too large to be ints are typed as
unsigned int if within range of that type, since it is more likely that they represent bit
patterns or masks, which are generally best treated as unsigned, rather than “real” numbers.
Little support was expressed for the old practice of permitting the digits 8 and 9 in an octal
constant, so it was dropped in C89.
A proposal to add binary constants was rejected due to lack of precedent and insufficient utility.
Despite a concern that a “lower-case-l” could be taken for the numeral one at the end of a
numeric literal, the C89 Committee rejected proposals to remove this usage, primarily on the
grounds of sanctioning existing practice.
搞明白了吧,出现这个告警,其实也是gcc提醒你该升级你的编译选项了。不过最安全的还是使用十六进制,或者加上UL或者ULL这样的说明。