Mail Archives: djgpp/1998/06/09/08:46:43
Shawn Hargreaves wrote:
> Not true. I'm not 100% sure of the rules for argument evaluation, but
> I
> suspect that different compilers are allowed to do these in whatever
> order they prefer. I do know for a fact that the ANSI standard
> explcitly
> says that the results are undefined if you use a ++ operator in a
> statement that also modifies the variable in some other way. Eg. if
> you
> were to write something like "i += i++;", the compiler is entitled to
> do
> whatever the hell it likes with that statement, including nothing. The
> error lies in the code, not the compiler...
Correct. ANSI 6.3:
Between the previous and next sequence point an object shall have
its stored value modified at most once by the evaluation of an
expression. Furthermore, the prior value shall be accessed only to
determine the value to be stored.
Note that this applies to _any_ modification of an object, not just
increments or additions. Thus statements like
i += i++;
and
*p++ = getchar(s);
are undefined. "Undefined," by the ANSI standard, means that _no_
restrictions are imposed -- crashing or emailing the President of the
United States is perfectly ANSI compliant.
--
Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com
Alcyone Systems / http://www.alcyone.com/max/
San Jose, California, United States / icbm:+37.20.07/-121.53.38
\
She glanced at her watch / . . . It was 9:23.
/ James Clavell
- Raw text -