[comp.lang.c] C abstract machine

mckeeman@wanginst.UUCP (04/14/87)

One of the nice sounding phrases in the x3j11 document is
_abstract_machine_.  I have been struggling to pull all of
what that means together into a place where I can make sense
of it.  I suspect that the Rationale contains the definition
but would be grateful if someone were to point out a precise
place to look.

My present conclusion is that for expressions, the abstract
machine demands that arithmetic be done on the operands as
defined by the grammar.  This ties down precisely the order
of commutative and associative operators (the focus of much
chitchat as of late).

Does it also tie down the order of evaluation of operands?
It seems reasonable that left-to-right would be required but
I have failed to find that written down.  If not, then even
(volatile) expressions are ill-defined for side-effects.
Example:

volatile int x = 1;
x = (3*(x++)) + (x++);

   =
 /   \
x     +
    /   \
   *     ++
  / \      \ 
 3  ++      x
      \
       x

will end up with x = 5 or 7.

Suppose x3j11 does require left-to-right evaluation.
That poses two problems. (1) The left side of an
assignment is evaluated prior to the right side 
although the result is going to be used only after the 
right side is evaluated.  Compiler writers won't
much like that since it can consume registers
for no reason.  (2) No compiler can compile 
optimized code on the fly, since each entire
_full_expression_ must be examined for a type
volatile variable which would force abstract
machine semantics.

-- 
W. M. McKeeman            mckeeman@WangInst
Wang Institute            decvax!wanginst!mckeeman
Tyngsboro MA 01879