3 ms·
No, it doesn't. Shifting by a wider amount than the width of the type, or an equal amount, is undefined in C and C++. That was done because different processors
by not2b 3y ago
No, it doesn't. Shifting by a wider amount than the width of the type, or an equal amount, is undefined in C and C++. That was done because different processors handled the case differently, meaning that any specification would give one processor a substantial time penalty compared to the competition. So the committee gave up on obtaining agreement and called it undefined.
- bxparks 3y agoBut why did they make it Undefined Behavior instead of Implementation Defined? I love the C language, but there are now so many UBs in the language, it is painful to use.
- ryao 3y agoIf they did, we would have two subtly different dialects of C for cyclic shift and zeroing shift, and possibly even worse, combinations of the two. That said, I am curious what the official answer is myself.