Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!mit-eddie!husc6!necntc!cullvax!drw From: drw@cullvax.UUCP Newsgroups: comp.lang.c Subject: Question about the new standard Message-ID: <812@cullvax.UUCP> Date: Wed, 18-Feb-87 11:50:25 EST Article-I.D.: cullvax.812 Posted: Wed Feb 18 11:50:25 1987 Date-Received: Thu, 19-Feb-87 20:27:46 EST Organization: Cullinet Software, Inc., Westwood, MA Lines: 39 I've got a question about the new standard. (Please discuss this only within the context of the standard, or possible desirable modifications of it. I don't want to hear "well, *my* compiler does it this way...") Consider the code: char *p; int i; i = *p++ == *p++; As far as I can tell, it is legitimate to increment p only once. The reasoning is: Evaluations of subexpressions are permitted to be interleaved in any way, except (1) a subexpression whose operator has a sequence point must not be interleaved with any other evaluation, and (2) the result of an assignment or prefix inc/decrement must be stored into its target before the resulting value is used. Since the above expression has no sequence points, we can evaluate it in the following order: 1 2 3 4 5 6 i = *p++ == *p++ A. Calculate p+1 (for 3) B. Calculate p+1 (for 6) C. Store p+1 (from A) in p (for 3) D. Store p+1 (from B) in p (for 6) E. Indirect (for 2 and 5) F. Compare (for 4) G. Assign (for 1) In fact, the same reasoning works for "*++p == *++p", because the above sequence of (abstract) execution gets the incremented values stored before they are used for indirection. Dale -- Dale Worley Cullinet Software UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw ARPA: cullvax!drw@eddie.mit.edu