C compiler weirdness?

David B.Anderson davea at quasar.wpd.sgi.com
Wed Apr 17 01:41:17 AEST 1991


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++))();

Recently, I quoted 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.'' as justifying the Release 3.3.x C compiler in compiling
the above statement.

I was wrong and the 3.3 C compiler is wrong.  The variable ``pc'' must
be incremented after the function address is calculated but *before* 
the function is called.

There is no ambiguity in the Standard, but I somehow misunderstood the
quoted sentence in the Standard.

I would like to thank Mark Bartelt (mark at cita.toronto.edu) for being 
persistent (via e-mail) and helping me to understand my error.

The C compiler bug is fixed in the next release of IRIX (4.0).

My apologies to anyone mislead by my error.

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