This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Weird result for modulus operation


Paolo Bonzini wrote:
Ang Way Chuang wrote:
Ang Way Chuang wrote:
Andrew Pinski wrote:
On Tue, Apr 29, 2008 at 9:08 PM, Ang Way Chuang <wcang@nav6.org> wrote:
Thanks for the speedy reply. But why this code:

        int a = 17, b = 16;
        a = a++ % 16;

results in a = 2 then? I think I need to know what is sequence point. I'll
google that.

As I mentioned, the code is undefined so it could be any value.

Is there any flag in gcc that can provide warning to code that relies on undefined behaviours?

Found it. -Wsequence-point which is enabled by -Wall. But gcc didn't fart out any warning with -Wall or -Wsequence-point flag :(

You found a bug, it does point out the problem with the second example here.

Huh? Now you got me confused. Since it is an undefined behaviour, gcc is free to whatever it likes. Though the answer given by the first and second examples show inconsistency in gcc in handling the undefined behaviour. I can't forward to gmane.comp.gcc.devel newsgroup with my account.



Paolo




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]