无法摆脱“这个十进制常量仅在 ISO C90 中是无符号的";警告 [英] Can't get rid of "this decimal constant is unsigned only in ISO C90" warning
本文介绍了无法摆脱“这个十进制常量仅在 ISO C90 中是无符号的";警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的哈希表实现中使用 FNV 哈希作为哈希算法,但我在这一行的问题标题中收到警告:
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:
unsigned hash = 2166136261;
我不明白为什么会这样,因为当我这样做时:
I don't understand why this is happening because when I do this:
printf("%u
", UINT_MAX);
printf("2166136261
");
我明白了:
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?
推荐答案
unsigned hash = 2166136261u; // note the u.
您需要一个后缀 u
来表示这是一个无符号数.如果没有 u
后缀,它将是一个带符号的数字.自从
You need a suffix u
to signify this is an unsigned number. Without the u
suffix it will be a signed number. Since
2166136261 > 2³¹ - 1 = INT_MAX,
这个整数文字会有问题.
this integer literal will be problematic.
这篇关于无法摆脱“这个十进制常量仅在 ISO C90 中是无符号的";警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文