哈希函数取自这里http://vak.ru/doku.php/proj/hash/sources
unsigned int RSHash (char *str, unsigned int len)
{
unsigned int b = 378551;
unsigned int a = 63689;
unsigned int hash = 0;
unsigned int i = 0;
for (i = 0; i < len; str++, i++) {
hash = hash * a + (unsigned char)(*str);
a = a * b;
}
return hash;
}
执行代码时出现错误
test2.c:23:24: runtime error: unsigned integer overflow: 63689 * 378551 cannot be represented in type 'unsigned int'
test2.c:22:30: runtime error: unsigned integer overflow: 72 * 2634698159 cannot be represented in type 'unsigned int'
我明白是因为unsignet int number溢出了,但是如果这个是专门内置到程序中的,那么如何避免这个警告的输出呢?因为 该程序不会崩溃,它可以运行。那些。似乎只是一个警告。
一切都是非常正确和合法的,因为无符号数的溢出在标准中有描述,不包含任何未定义的行为,不是实现定义的(与有符号溢出不同),所以代码中的一切都是正常的,可以安全地工作。