C语言 无法摆脱“此十进制常量仅在 ISO C90 中无符号”警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2347936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't get rid of "this decimal constant is unsigned only in ISO C90" warning
提问by rfgamaral
I'm using the FNV hash as a hashing algorithm on my Hash Table implementation but I'm getting the warning in the question title on this line:
我在我的哈希表实现中使用 FNV 哈希作为哈希算法,但我在这一行的问题标题中收到警告:
unsigned hash = 2166136261;
I don't understand why this is happening because when I do this:
我不明白为什么会这样,因为当我这样做时:
printf("%u\n", UINT_MAX);
printf("2166136261\n");
I get this:
我明白了:
4294967295
2166136261
Which seems to be under the limits of my machine...
这似乎在我机器的限制下......
Why do I get the warning and what are my options to get rid of it?
为什么我会收到警告以及我有哪些选择可以摆脱它?
回答by kennytm
unsigned hash = 2166136261u; // note the u.
You need a suffix uto signify this is an unsigned number. Without the usuffix it will be a signed number. Since
您需要一个后缀u来表示这是一个无符号数。如果没有u后缀,它将是一个有符号的数字。自从
2166136261 > 231 - 1 = INT_MAX,
this integer literal will be problematic.
这个整数文字会有问题。

