comma operator

Tom Karzes karzes at mfci.UUCP
Sat Aug 5 04:40:47 AEST 1989


In article <3287 at ohstpy.mps.ohio-state.edu> SMITHJ at ohstpy.mps.ohio-state.edu writes:
>Maybe I'm mistaken, but I'm sure that all the documentation I've read warns
>that the *comma* operator ----does not----- guarantee evaluation in any order.
>Specifically, the Microsoft 5.0 manual mentions this.

I find that difficult to believe.  You're probably confusing the comma
operator with the comma argument list separator.  The former guarantees
left-to-right evaluation in any implementation which has any business
calling itself C.  The latter does not guarantee any order of evaluation.

See section 7.15 of the original C reference manual, section 7.15 of the
C++ reference manual, and section A7.18 of the new C reference manual (in
the latest edition of K&R).  These sections clearly explain the left-to-right
semantics of the comma operator, and conclude with the following example:

    f(a, (t=3, t+2), c)

It states that this [function reference] has three arguments, the second
of which has the value 5.

Similarly, ANSI C describes the comma operator as having a sequence point
after the evaluation of the left operand, and concludes with the IDENTICAL
example shown above (this is in section 3.3.17 of the copy of the draft
I'm looking at).

As I said, you've almost certainly confused the comma operator with the
comma argument list separator.  I don't believe the Microsoft people
would have been stupid enough not to support the comma operator correctly
(if they really were that stupid, then they should call their language C--,
because it certainly isn't C).



More information about the Comp.lang.c mailing list