comma operator: keep away?

Sho Kuwamoto sho at pur-phy
Sun Apr 23 12:21:35 AEST 1989


In article <19926 at iuvax.cs.indiana.edu> bobmon at iuvax.cs.indiana.edu (RAMontante) writes:
<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,
<<[..]
<[..]
<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)?

When it comes right down to it, there are lots of unneccessary features.
for, while, case, do while, the entire preproccessor, array indexing,
->, ?:, structs, unions, etc.  All of these could be done with goto and
explicit pointer manipulation, etc., if you wanted to.  But why?

As for another example where you could use the comma operator usefully,
how about...

	for(i=0, p=head; p->next != NULL; i++, p=p->next)
or something.

-Sho



More information about the Comp.lang.c mailing list