pete wrote:
> Joachim Schmitz wrote:
>>
>> Philip Potter wrote:
>>> CBFalconer wrote:
>
>>>> However, barring arithmetic
>>>> overflow, ((x << 2) == (x * 4)) is guaranteed for unsigned x.
>>>>
>>> Again, not so. For x == 1,
>>> no overflow occurs but UB does occur so no
>>> guarantees exist.
>> Chuck wrote "for unsigned x"
>
> /* BEGIN new.c */
>
> #include <stdio.h>
>
> int main(void)
> {
> unsigned x = 0u  1;
>
> if ((x << 2) == (x * 4)) {
> puts("In that case, arithmetic overflow, is irrelevant.");
> }
> return 0;
> }
>
> /* END new.c */
>
> N869
> 6.2.5 Types
> [#9]
> A computation involving unsigned operands
> can never overflow, because a result that cannot be
> represented by the resulting unsigned integer type is
> reduced modulo the number that is one greater than the
> largest value that can be represented by the resulting type.
>
> 6.5.5 Multiplicative operators
> [#4] The result of the binary * operator is the product of
> the operands.
>
> 6.5.7 Bitwise shift operators
> [#4] The result of E1 << E2 is E1 leftshifted 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.
Yes? So where's the UB Philip claimed?
Bye, Jojo
