Re: Weird result for modulus operation

2008-04-30 Thread Robert Dewar
Ang Way Chuang wrote: Andrew Pinski wrote: On Tue, Apr 29, 2008 at 8:50 PM, Ang Way Chuang <[EMAIL PROTECTED]> wrote: abc.a = abc.a++ % abc.b; You are assigning to abc.a twice without a sequence point inbetween so this code is undefined as the order of evaluation of expressions withou

Re: Weird result for modulus operation

2008-04-30 Thread Ang Way Chuang
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.

Re: Weird result for modulus operation

2008-04-30 Thread Paolo Bonzini
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

Re: Weird result for modulus operation

2008-04-30 Thread Ang Way Chuang
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 <[EMAIL PROTECTED]> 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

Re: Weird result for modulus operation

2008-04-29 Thread Paolo Bonzini
Ang Way Chuang wrote: Ang Way Chuang wrote: Andrew Pinski wrote: On Tue, Apr 29, 2008 at 9:08 PM, Ang Way Chuang <[EMAIL PROTECTED]> 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 i

Re: Weird result for modulus operation

2008-04-29 Thread Ang Way Chuang
Ang Way Chuang wrote: Andrew Pinski wrote: On Tue, Apr 29, 2008 at 9:08 PM, Ang Way Chuang <[EMAIL PROTECTED]> 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

Re: Weird result for modulus operation

2008-04-29 Thread Ang Way Chuang
Andrew Pinski wrote: On Tue, Apr 29, 2008 at 9:08 PM, Ang Way Chuang <[EMAIL PROTECTED]> 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 men

Re: Weird result for modulus operation

2008-04-29 Thread Andrew Pinski
On Tue, Apr 29, 2008 at 9:08 PM, Ang Way Chuang <[EMAIL PROTECTED]> 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 c

Re: Weird result for modulus operation

2008-04-29 Thread Ang Way Chuang
Andrew Pinski wrote: On Tue, Apr 29, 2008 at 8:50 PM, Ang Way Chuang <[EMAIL PROTECTED]> wrote: abc.a = abc.a++ % abc.b; You are assigning to abc.a twice without a sequence point inbetween so this code is undefined as the order of evaluation of expressions without a sequence point is

Re: Weird result for modulus operation

2008-04-29 Thread Andrew Pinski
On Tue, Apr 29, 2008 at 8:50 PM, Ang Way Chuang <[EMAIL PROTECTED]> wrote: > abc.a = abc.a++ % abc.b; You are assigning to abc.a twice without a sequence point inbetween so this code is undefined as the order of evaluation of expressions without a sequence point is unspecified. Thanks, A