comma operator

Blair P. Houghton bph at buengc.BU.EDU
Sun Aug 6 03:12:57 AEST 1989


In article <9736 at alice.UUCP> debra at alice.UUCP () writes:
>
>	if (e)
>		printf("Hi\n"),return;
>
>gives syntax error. (at least in the compilers i've tried)
>
>	if (e)
>		printf("Hi\n"),exit();
>
>compiles fine. It's just that "return" is treated differently.

BECAUSE IT'S A STATEMENT!!

Pardon the tone, but this is actually a joke I'm telling, here...
Several of you will get it.  Go to the next article while I explain...


The original examples in this subject thread used

	fprintf(...) , exit(0) ;

and I made the mistake of thinking these were statements and I flamed
on that point and I was soundly thrashed for my misstatements.

The return statement, however, is just that, a statement.  The things
on either side of a comma opertor must be expressions.  The element
formed by expressions and comma operators is itself an expression.
You can't stick for-loops in a comma-expression, for example.

The syntax summary at the back of K&R is probably the best place
to find a concise definition of the distinction between expressions
and statements

				--Blair
				  "Vindication is satisfying,
				   which is also an expression."



More information about the Comp.lang.c mailing list