Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!henry
From: henry@utzoo.UUCP (Henry Spencer)
Newsgroups: net.lang.c
Subject: Re: op= operators
Message-ID: <4420@utzoo.UUCP>
Date: Thu, 4-Oct-84 13:33:27 EDT
Article-I.D.: utzoo.4420
Posted: Thu Oct  4 13:33:27 1984
Date-Received: Thu, 4-Oct-84 13:33:27 EDT
References: <460@astrovax.UUCP>
Organization: U of Toronto Zoology
Lines: 25

> I am not sure how K&R specify that
> 	*ptr++ += 2;
> should be evaluated. Page 191 says only that the behaviour of E1 op= E2
> is the same as E1 = E1 op E2, but does that mean in this case
> 	*ptr++ += *ptr++ + 2;
> 	*ptr += *ptr++ + 2;
> or
> 	*ptr++ += *ptr + 2; ? (and what does the first form mean?)
> 
> For out 4.2 bsd compiler, the last form is used, with the incrementation of
> the pointer after the addition of 2. Is this guaranteed by the standard?

If you look carefully at page 191, you'll see that it also says "however,
E1 is evaluated only once".  So there is only one ++ involved.  The right
expansion for this is:

	*ptr = *ptr + 2;
	ptr++;

Note that no expansion with only one statement is really correct, since
the order of side effects (++ and =) within a statement is pretty much
undefined in C.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry