From: utzoo!decvax!harpo!npoiv!alice!research!dmr
Newsgroups: net.lang
Title: if statement ambiguity and the C preprocessor
Article-I.D.: research.303
Posted: Thu Sep 23 00:04:46 1982
Received: Thu Sep 23 05:01:23 1982

Jan Edler wondered how to define a macro in C that expands to an if statement,
and doesn't cause trouble when it appears amid if's and else's.
The cleanest way to handle the if ambiguity
(or at least to push the dirt under the smallest rug) is to define your
macro as follows

	#define mymacro	if (e1) s1; else

Then both the uses

	if (e2)
		mymacro;
	foo();

and

	if (e2)
		mymacro;
	else
		goo();
	foo();

get parsed correctly and the user doesn't have to remember that the macro
is special syntactically.

	Dennis Ritchie
	  (with thanks to Doug McIlroy)