C compiler weirdness?

David B.Anderson davea at quasar.wpd.sgi.com
Sat Apr 13 06:49:11 AEST 1991


In article <1991Apr12.175909.5194 at helios.physics.utoronto.ca> mark at cita.toronto.edu writes:
>David Blythe wrote ...
>
>| I recently dug up a copy of the hoc calculator described in kernighan & pike
>| only to discover that the C compiler does not increment pc until after the
>| function call returns in the following statment:
>|                   (*(*pc++))();
>| whereas the rest of the program is assuming it is done before the function is
>| actually called.  Is the compiler interpretation supposed to be implementation
>| dependent?  I would suspect not, but then I can't believe no one else has
[ ]
>Sorry, but this example is irrelevant to the bug being reported (and it is a
>bug, if the behaviour of the SGI compiler is in fact what David reports it to

Since Mark Bartelt claims that the compiler is wrong, I'll step up to its
defense (I do not claim that the compiler version used is ANSI C):

ANSI C: 3.3.2.2, page 42. line 20.
``The order of evaluation of the function designator, the arguments,
and subexpressions within the arguments is unspecified, but there is
a sequence point before the actual call.''

The Standard does not say whether the sequence point is before or
after the evaluation of the function designator.

The following is thus _a_ legal sequence:
        evaluate arguments (none in the case above)
        sequence point (arguments evalation complete)
        evaluate function designator
        call function
        increment pc
        statement sequence point

So IMO our code generation is legal in this case.  (case dismissed :-)

Regards,
[ David B. Anderson  Silicon Graphics  (415)335-1548  davea at sgi.com ]
[``What can go wrong?''                           --Calvin to Hobbes]



More information about the Comp.sys.sgi mailing list