int左移32位的行为未定义

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.

 

相关文章:

  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
  • 2021-08-01
  • 2021-08-31
  • 2021-08-08
猜你喜欢
  • 2021-11-21
  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
  • 2021-07-24
  • 2022-12-23
  • 2021-12-22
相关资源
相似解决方案