“warning: this decimal constant is unsigned only in ISO C90”的解决办法

1. 问题描述:

     warning: this decimal constant is unsigned only in ISO C90

2.  在程序编译的时候出现:warning: this decimal constant is unsigned only in ISO C90
精简代码如下:
# include <stdio.h > 

int main( int argc, char *argv[])
{
   unsigned int i = 4286545791;
  printf( "%d\n",i);

   return 0;
}
3. 编译时,GCC编译器会抛出以下warning:
$ gcc -o test test.c 
test.c: In function ‘main’ :
test.c:4: warning : this decimal constant is unsigned onlIy in ISO C90

4. c的标准里面描述:

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.

C语言中常量值默认是一个32位的有符号整型数。由于2394967295无法用32位的有符号整型数表示,所以会有报警产生,即该问题通常出现在默认型存储不够的情况下。


5. 解决方法:

1 在常数后面增加一个U标识,如果是long或longlong类型加UL或ULL,如4286545791U进行类型强制转换,这样就不会报警了
2 使用十六进制的数字,如0xFFFFFFFF
3 使用gcc -std=c99 用99标准来编译

  • 9
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值