gpt4 book ai didi

无法摆脱 "this decimal constant is unsigned only in ISO C90"警告

转载 作者:太空狗 更新时间:2023-10-29 16:23:04 30 4
gpt4 key购买 nike

我在我的哈希表实现中使用 FNV 哈希作为哈希算法,但我在这一行的问题标题中收到警告:

unsigned hash = 2166136261;

我不明白为什么会这样,因为当我这样做时:

printf("%u\n", UINT_MAX);
printf("2166136261\n");

我明白了:

4294967295
2166136261

这似乎在我的机器的限制之下......

为什么我会收到警告?我有哪些选择可以消除它?

最佳答案

unsigned hash = 2166136261u; // note the u.

您需要一个后缀 u 来表示这是一个无符号数。如果没有 u 后缀,它将是一个带符号的数字。由于

2166136261 > 2³¹ - 1 = INT_MAX,

这个整数文字会有问题。

关于无法摆脱 "this decimal constant is unsigned only in ISO C90"警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2347936/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com