comma operator: keep away?

Doug Gwyn gwyn at smoke.BRL.MIL
Sun Apr 23 10:34:01 AEST 1989


In article <19926 at iuvax.cs.indiana.edu> bobmon at iuvax.cs.indiana.edu (RAMontante) writes:
>I find that neither one uses a comma in getc, getchar, putc, putchar, or
>anywhere else, except to separate parameters.

Ok, I picked a bad example.  However, many macros need to accomplish
more than one thing and cannot do so without the aid of some such
trickery as
	((expr1) & 0 | (expr2))
which is more simply expressed as
	(expr1, expr2)

>Nonetheless I think I get the idea, but that doesn't mean that the code
>wouldn't work without the comma (does it?) -- couldn't the same semantics
>be reproduced by a series of statements culminating in the final
>expression of the parentheses (presumably for assignment purposes)?

No!  A series of statements cannot be used as a subexpression.

Of course -- as I just demonstrated -- there are ways to avoid ever using
a comma operator, but then all you really need is a Turing machine, right?
So why does C provide more than the logical minimum?  It's because it was
designed to be USED for real programming, and matters of convenience are
quite relevant for that.



More information about the Comp.lang.c mailing list