comma operator: keep away?

RAMontante bobmon at iuvax.cs.indiana.edu
Sun Apr 23 04:49:56 AEST 1989


gwyn at brl.arpa (Doug Gwyn) <10092 at smoke.BRL.MIL> :
-	[ me ]
->Is there a circumstance in which the comma operator is required, where
->the compound statement cannot be broken into multiple statements?
-
-You've got to be kidding -- a comma expression is an expression,
-whereas multiple statements are not an expression.  Thus the comma
-operator is useful in contexts where semicolon-terminated statements
-would not be.  Look at the definition of putc() in most implementations
-of <stdio.h> for an example.


"You've got to be kidding?" In fact someone else suggested getchar() as
an example.  Looking at the Turbo C stdio.h, and the ULTRIX v1.7 stdio.h,
I find that neither one uses a comma in getc, getchar, putc, putchar, or
anywhere else, except to separate parameters.

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)?

I said "required", not "useful".



More information about the Comp.lang.c mailing list