[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-hackers
Subject:    Re: some weird C
From:       Warner Losh <imp () village ! org>
Date:       1999-01-31 19:46:29
[Download RAW message or body]

In message <199901311035.UAA28754@zeus.theinternet.com.au> Andrew Kenneth Milton writes:
: +----[ Daniel C. Sobral ]---------------------------------------------
: | Andrew Kenneth Milton wrote:
: | > 
: | > +----[ Malartre ]---------------------------------------------
: | > |
: | > | I was expecting 9, not 10.
: | > | since 4+5=9?
: | > 
: | > x is pre-incremented, making it 5 *before* the += takes effect.
: | > 
: | > This is correct behaviour.
: | 
: | Explain the 8 then... if x++ takes effect *after* +=, it should have
: | been 9, right?
: 
: No. the time at which a post increment operation takes place is
: undefined, but, before the next *expression*

x += x++; is undefined.  That's the explaination.

If x is 4 before, then it could be 8, 9, 10 or 1045 after the
expression, and they would all be right.

Waarner

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic