是否是未定义行为(UB):
?
如果答案包含对 C 标准的引用,我将不胜感激。
请参阅 ISO C 标准 (ISO/IEC 9899),6.5.7 位移运算符,第 4 段:
E1结果<< E2 is E1 left-shifted E2 bit positions; vacated bits are filled with zeros. If E1 has an unsigned type, the value of the result is E1 × 2E2, reduced modulo one more than the maximum value representable in the result type. If E1 has a signed type and nonnegative value, and E1 × 2E2 is representable in the result type, then that is the resulting value; otherwise, the behavior is undefined.
0
<<
32 和 0LL <<
64 都会导致 C 中的未定义行为 (UB)。