delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/09/08:46:43

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: printf bug ???
Date: Fri, 05 Jun 1998 18:44:34 -0700
Organization: Alcyone Systems
Lines: 42
Message-ID: <35789F02.1EF059F7@alcyone.com>
References: <Pine DOT GSO DOT 3 DOT 96 DOT 980605144528 DOT 10548A-100000 AT bert DOT eecs DOT uic DOT edu>
<35784F8A DOT AB5D79CC AT gpu DOT srv DOT ualberta DOT ca> <MYoEcGATNFe1Ewts AT talula DOT demon DOT co DOT uk>
NNTP-Posting-Host: charmaine.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019