Beautiful side-effects! (q = q++)
Rodney Radford
sasrer at unx.sas.com
Fri Jun 28 00:12:20 AEST 1991
In article <1991Jun26.154734.14439 at dsuvax.uucp> rolfe at dsuvax.uucp (Timothy J. Rolfe) writes:
>Beautify, beautiful side effect!!
>
>As it stands, "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.
ANSII C says the behaviour of the above line is indetermined
(ie: implementation dependent), and should be avoided in writing portable
C programs (to more that one machine, or more that one compiler, or
possibly to different versions of the same compiler...).
The reason ANSII could not set a standard on this is that through the years
so many different versions of C existed and handled this differently. Also
should be avoided statements such as:
array[i++] = i;
--- or ---
function(++k,k,k++)
These are just other examples of indeterminate side-effect expressions....
--
Rodney Radford || Computer Graphics/Imaging
sasrer at unx.sas.com || SAS Institute, Inc.
(919) 677-8000 x7703 || Cary, NC 27513
More information about the Comp.lang.c
mailing list