[LLVMdev] Why "I = ++I" instead of "++I" in COFFDump.cpp ?

Richard legalize at xmission.com
Mon Apr 7 15:49:01 PDT 2014


OK, of course I found it after I asked for the section reference :-)

In article <E1WXHz7-0004mT-NQ at shell.xmission.com>,
    Richard <legalize at xmission.com> writes:

> If you could point me to the appropriate section of the Nov.  2012 Draft
> Standard where I could read about the sequence point rule, I would be very
> appreciative as I would like to understand this better.

Is it here?

1.9.15

    "Except where noted, evaluations of operands of individual
    operators and of subexpressions of individual expressions are
    unsequenced. [...] The value computations of the operands of
    an operator are sequenced before the value computation of the
    result of the operator. If a side effect on a scalar object is
    unsequenced relative to either another side effect on the same
    scalar object or a value computation using the value of the same
    scalar object, the behavior is undefined.

    Example:

    void f(int, int);
    void g(int i, int* v) {
      i = v[i++]; // the behavior is undefined
      i = 7, i++, i++; // i becomes 9

      i = i++ + 1; // the behavior is undefined
      i = i + 1; // the value of i is incremented

      f(i = -1, i = -1); // the behavior is undefined
    }"

The middle group of statements seems to be the one that applies here,
although they use i++ and not ++i, the point seems to be the same.
-- 
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
     The Computer Graphics Museum <http://ComputerGraphicsMuseum.org>
         The Terminals Wiki <http://terminals.classiccmp.org>
  Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com>



More information about the llvm-dev mailing list