C compiler weirdness? (a final(?) postscript)
Mark Bartelt
sysmark at aurora.physics.utoronto.ca
Wed Apr 17 04:54:59 AEST 1991
In article <97603 at sgi.sgi.com>
davea at quasar.wpd.sgi.com (David B.Anderson) writes:
[ regarding David Blythe's question about the compiler's misbehaviour
when dealing with (*(*pc++))() ]
| 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.
Thanks for the thanks, but most of the credit really should go to Henry
Spencer (UofT's local source of ultimate oracular wisdom on anything and
everything related to C, UNIX, and a host of other things), who offered
his interpretation of what the standard says. For those of you who may
be interested, here are his comments:
| ANSI C's sequence-point stuff is, in general, enough to make your head
| ache. However, in this case the standard is clear [ ... ]
|
| 3.3.2.2: "The order of evaluation of the function designator,
| the arguments, and the subexpressions within the arguments is unspecified,
| but there is a sequence point before the actual call."
|
| This very issue -- increments vs. function calls -- was a hotly-debated
| point both before and during standardization, hence the very explicit
| resolution of it.
Consulting Henry also afforded an opportunity to get my own (incorrect)
opinions on a couple of matters straightened out. Specifically:
(1) In one of my previous postings, I offered biblical quotes (K&R-2) to
support my contention that the compiler was misbehaving. Dave Anderson
pointed out that doing so was wrong (albeit a common mistake), and that
the standard is now the only proper arbiter of correct behaviour. Henry
backed this up, saying:
| your correspondent is correct in saying that nothing short of the
| actual standard is authoritative on the fine points. K&R2 not only made no
| attempt to be authoritative, but is wrong in small things due to having
| been written based on a late draft rather than the final standard.
(2) At one point, I asserted that
Since the incrementing of an
operand (after noting its value) is part of the definition of the semantics
of the postfix ++ operator, it seems quite clear that postfix incrementing
has to be treated as an atomic operation.
Wrongo. Henry offers a correction:
| There has never been any promise that postfix ++ was atomic, and indeed
| some compilers do postpone the increment a little in some circumstances.
Oh, well, it just goes to prove that no matter how cocky and self-confident
I seem to be, there'll always be an opportunity to embarrass myself in public
with a mistake or two, even when I'm right! :-)
Mark Bartelt 416/978-5619
Canadian Institute for mark at cita.toronto.edu
Theoretical Astrophysics mark at cita.utoronto.ca
More information about the Comp.sys.sgi
mailing list