order-of-evaluation

utzoo!decvax!duke!mcnc!ncsu!fostel utzoo!decvax!duke!mcnc!ncsu!fostel
Mon Feb 28 10:26:26 AEST 1983



    The example on page 50 does not really answer the question posed along
    with the example "a[++i]=++i;". At least not in a pleasant way. The
    assignment statement itself is an expression, with the rhand and lhand
    sides simply sub-expressions. In the case of "a[i]=++i", the lhand side
    is not quite sufficently complex to illustrate the problem that was
    asked about.  Perhaps a better way to phrase the question is this:

        Will the expression evaluation order ever be something other then
        left-depth first, or right-depth first, or breadth firsr, or ....

    In other words, can one make any assumptions such as, once it has started
    on the lhand side will it go all the way there before starting on the
    rhand side?  The example on p 50 is not compelling since once it has
    started on the lhand side, it is effectively finished there. Adding
    the additional level of evaluation makes it a bit more difficult to
    see the example as a definitive answer.  BUT ...

    Ignore the example on p50 and look at the words. Don't assume anything
    about the order of execution. An optimizer will commonly reshuffle such
    things even if there is some higher level model such as left-depth-first,
    or whatever.  ANYWAY, NEVER WRITE UCKY CODE LIKE THAT -- it gives c a
    bad name.
    ----GaryFostel----
                      decvax!duke!mcnc!ncus!fostel



More information about the Comp.lang.c mailing list