无法摆脱的"这小数常量仅ISO C90&QUOT符号;警告 [英] Can't get rid of "this decimal constant is unsigned only in ISO C90" warning

查看:483
本文介绍了无法摆脱的"这小数常量仅ISO C90&QUOT符号;警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的哈希FNV作为我的哈希表的实现哈希算法,但我发现在这条线的问题的标题警告:

 无符号哈希= 2166136261;

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

 的printf(%U \\ N,UINT_MAX);
的printf(2166136261 \\ n);

我得到这样的:

  4294967295
2166136261

这似乎是在我的机器的极限......

为什么我得到警告,什么是我的选择,以摆脱它?


解决方案

 无符号哈希= 2166136261u; //注意的U。

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

  2166136261> 2³¹ -  1 = INT_MAX,

此整数文本将是有问题的。

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\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?

解决方案

unsigned hash = 2166136261u; // note the 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&QUOT符号;警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆