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);
}
1099511628211is also too big for a (32-bit)long; add theULLsuffix there, too.AFAIK, GCC 4.x supports
long longfor 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++ --versionoutput 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.