int左移32位的行为未定义/Coverity

int左移32位的行为未定义

Coverity 代码静态安全检测

Is Shifting more than 32 bits of a uint64_t integer on an x86 machine Undefined Behavior?

 

uint64_t s = 1 << 32;

uint64_t s = 1ULL << 32;

Note, however, that if you write a literal that fits into 32 bits, e.g. uint64_t s = 1 << 32 as surmised by @drhirsch, 
you don't actually shift a 64-bit value but a 32-bit one. That is undefined behaviour. The most common results are a
shift by shift_distance % 32 or 0, depending on what the hardware does.

 

posted @ 2016-10-08 16:10  静之深  阅读(1208)  评论(0编辑  收藏  举报