Xref: utzoo alt.folklore.urban:16741 comp.lang.c:40535 alt.folklore.computers:13207 Path: utzoo!utgpu!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ox.com!emory!samsung!uunet!zephyr.ens.tek.com!uw-beaver!fluke!kurt From: kurt@tc.fluke.COM (Kurt Guntheroth) Newsgroups: alt.folklore.urban,comp.lang.c,alt.folklore.computers Subject: Re: Beautiful side-effects! (q = q++) Message-ID: <1991Jun27.163643.1223@tc.fluke.COM> Date: 27 Jun 91 16:36:43 GMT References: <15520@exodus.Eng.Sun.COM> <1991Jun25.151408.1024@ux1.cso.uiuc.edu> <1991Jun26.154734.14439@dsuvax.uucp> Organization: John Fluke Mfg. Co., Inc., Everett, WA Lines: 14 > "q = q++;" SHOULD leave q unchanged: evaluating the > right hand side we get a value (q BEFORE the increment). That is > the value that is supposed to go to the left hand side. The question > is WHEN the post-increment is done. K&R says nothing about when the increment's side effect is processed, and ANSI says specifically that it is undefined. The side effect may be applied AFTER the assignment. You are probably used to the informal PDP11 semantics where q++ generates an increment instruction, but no all architectures or compilers choose this method. A better example is *p++ = *p++; which has three side effects that may be processed in arbitrary order.