Weird result for modulus operation
Ang Way Chuang
wcang@nav6.org
Wed Apr 30 14:04:00 GMT 2008
Paolo Bonzini wrote:
>>>>>>> Thanks for the speedy reply. But why this code:
>>>>>>>
>>>>>>> int a = 17, b = 16;
>>>>>>> a = a++ % 16;
>>
>> Huh? Now you got me confused. Since it is an undefined behaviour, gcc
>> is free to whatever it likes.
>
> Sure, but if you ask gcc to signal a warning, it is supposed to do so.
> :-) It is a bug that gcc with -Wsequence-point signals a warning for "a
> = a++ % 16" but not when you use abc.a.
>
Oic, thank you for the clarification. I didn't notice that the warning
works for a = a++ % 16 because I only tried the -Wsequence-point flag on
abc.a example.
>> Though the answer given by the first and second examples show
>> inconsistency in gcc in handling the undefined behaviour.
>
> That's not a problem. GCC does not have to be consistent. But both
> should be warned about.
>
>> I can't forward to gmane.comp.gcc.devel newsgroup with my account.
>
> No problem, you can delete it.
>
> Paolo
>
More information about the Gcc
mailing list