Nope, on 16-bit platforms a 16-bit left shift has a very different result from a 16-bit left shift on a 32 bit platform.
It's basically a question about knowing when you'll get burned by the size of int varying.
It's basically a question about knowing when you'll get burned by the size of int varying.
(i >= i) // 1
((i >= i) << i) // 0x10000 or 0
(((i >= i) << i) >> i) // 1 or 0
(((((i >= i) << i) >> i) <= i)) // ((0 or 1) <= 16) == 1
Where did I go wrong?UB.
> If the value of the right operand is negative
> or is greater than or equal to the width of
> the promoted left operand, the behavior is
> undefined"
(http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1570.pdf - ISO/IEC 9899:201x (C11 Working Draft N1570): 6.5.7 Bitwise shift operators)