comma operator
King Su
wen-king at cit-vax.Caltech.Edu
Wed Aug 2 13:36:55 AEST 1989
In article <3553 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) writes:
>In article <1989Jul28.174033.12734 at jarvis.csri.toronto.edu> flaps at dgp.toronto.edu (Alan J Rosenthal) writes:
<>
>>dandb at k.gp.cs.cmu.edu (Dean Rubine) writes:
<>>I also occasionally use the comma to save braces:
>>> if((f = fopen(file, "r")) == NULL)
<>> fprintf(stderr, "Can't open %s\n", file), exit(2);
>>
<>Funny, I use braces to save commas:
>> if ((f = fopen(file, "r")) == NULL) {
<> fprintf(stderr, "Can't open %s\n", file);
>> exit(2);
<> }
>
<Funny, you didn't notice the syntactic error of putting a statement
>as the comma's operand, which may only be an expression...
Funny, you didn't notice that both fprintf(...) and exit(...) are
expressions.
My rule about style is that there is no rule. You can use NULL, TRUE,
comma, or even goto, as long as the end product is easier to understand
as a result of their use. You can even change your style from time to
time, if it helps.
--
/*------------------------------------------------------------------------*\
| Wen-King Su wen-king at vlsi.caltech.edu Caltech Corp of Cosmic Engineers |
\*------------------------------------------------------------------------*/
More information about the Comp.lang.c
mailing list