Right shifting a number literal

72 Views Asked by At

I'm wondering about the behavior of number literals and right-shifting, in relation to their signed-ness. Right shifting a signed integer variable can have multiple behaviors depending on the compiler, but does this apply to literals as well?

It's probably easier to ask in code:

// edited the question's values from 0x80000000 to this to avoid an integer promotion
uint32_t x = 0x7F000000 >> 4;
uint32_t y = 0x7F000000u >> 4;
uint32_t z = 0x7F000000u >> 4u;

assert(x == y && y == z);

Could this code ever fail it's assertion, given a compliant C++17 compiler?

0

There are 0 best solutions below