comma operator

Steven Kilbane skilbane at zaphod.axion.bt.co.uk
Thu Aug 3 17:32:05 AEST 1989


>From article <2963 at solo6.cs.vu.nl>, by roemer at cs.vu.nl (Roemer Lievaart):
> tada at athena.mit.edu (Michael Zehr) writes:
> I often write:
> 
> 	if (something_goes(wrong) )
> 		fprintf(stderr, "%s: I give up!\n", argv[0] ) ,
> 		exit(2) ;
> 
> Of course it's no better than using { ; }, but it's not worse either.

Personally, I think it is worse that {;}. If you have something of the form

	x = Expr1 , Expr2;

then Expr2 will be assigned to x, rather than Expr1. If you rewrite them as

	x = Expr1,
	    Expr2;

you're relying on (a) the indentation and (b) being very careful, to notice you
have a comma instead of a semicolon. Inserting extra code might be nasty:

	x= Expr1,
	   Expr3;
	   Expr2;

*BOOM*...
-oOo-oOo-oOo-oOo-oOo-oOo-oOo-oOo-oOo-oOo-oOo-oOo-oOo-oOo-oOo-oOo-oOo-oOo-oOo-oOo
Stephen Kilbane                      |Email: skilbane at uk.co.bt.axion
British Telecom Research Laboratories|or smk-a at uk.ac.york.minster (or, if that
Martlesham Heath                     |doesn't work, root at uk.ac.york.softeng - 
Ipswich IP5 7RE (0473 646638)        |not me, but it may be passed on....
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Disclaimer: Who? Me? Nah - must have been someone else when my back was turned!
Quotes: "If silence is golden, music is platinum"
        "'You haven't lived till you've died in MUD' - I live a lot!"
        "(If platinum is to gold, what is to golden?)"[This space to rent]



More information about the Comp.lang.c mailing list