gcc 4.1.2:错误:整数常量对于“long”来说太大;类型
我编译了一段关于哈希函数的代码并得到了错误:整数常量对于“long”类型来说太大了。我用谷歌搜索了一下,它说要添加后缀“ULL”,但我确实有 ULL 作为后缀。这个后缀仅受 gcc 4.4.1 支持,我的机器上只有 gcc 4.1.2,并且不允许我安装新的编译器。有什么办法可以更改代码来解决问题吗?
谢谢, -托尼
unsigned long long hash(string k){ //FNV hash
unsigned long long x = 14695981039346656037ULL;
for (unsigned int y=0;y<k.length();y++){
x = x ^ (k[y]);
x = x * 1099511628211;
}
return (x);
}
I compiled a piece of code about hash function and got error: integer constant is too large for ‘long’ type. I did Google it and it said to add the suffix "ULL", but I did have ULL as suffix. This suffix is supported only by gcc 4.4.1 and I only have gcc 4.1.2 on the machine and I'm not allowed to install a new compiler. Is there any way to change the code so fix the problem?
Thanks,
-Tony
unsigned long long hash(string k){ //FNV hash
unsigned long long x = 14695981039346656037ULL;
for (unsigned int y=0;y<k.length();y++){
x = x ^ (k[y]);
x = x * 1099511628211;
}
return (x);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
1099511628211
对于(32 位)long
来说也太大了;也添加ULL
后缀。AFAIK,GCC 4.x 支持所有 x 的
long long
。事实上,我说过 GCC 3.x 支持long long
,至少对于更新的 x 值是这样。在 MacOS X 10.7.2 上以 32 位或 64 位模式使用 G++ 4.6.1 时,我很难让您的代码触发任何警告。但是,我可以从 XCode 4.x 的 LLVM 编译器得到投诉(
g++ --version
输出以i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2 开头。 1(基于 Apple Inc. build 5658)(LLVM build 2335.15.00)
)确实会抱怨,直到我添加第二个ULL
,但前提是我在 32 位模式下编译。如果在 64 位模式下使用它,它也不会抱怨。1099511628211
is also too big for a (32-bit)long
; add theULL
suffix there, too.AFAIK, GCC 4.x supports
long long
for all x. Indeed, I'd have said that GCC 3.x supportedlong long
, at least for the more recent values of x.I'm having difficulty making your code trigger any warning, using G++ 4.6.1 on MacOS X 10.7.2 in either 32-bit or 64-bit mode. However, I can get the complaint from the LLVM compiler from XCode 4.x (
g++ --version
output starts withi686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
) does complain until I add the secondULL
, but only if I compile in 32-bit mode. If that is used in 64-bit mode, it doesn't complain either.您可以编写一个计算结果为相同数字的常量表达式:
这使用 g++ 4.2.1 进行编译
You can write a constant expression that evaluates to the same number:
This compiles with g++ 4.2.1
试试这个:
这两个数字是使用以下示例程序获得的:
Try this:
These two numbers were obtained using this sample program: