C-Debug package ... (a la "context-independent macros")

Peter K. Lee pkl at daisy.UUCP
Sat Jan 26 17:49:30 AEST 1985


> Whenever I define a macro to be an expression, I put parens around it
> to avoid surprises.  Similarly, whenever I define a macro to be a
> (compound) statement, I put braces around it.  There are two places
> where braces cause problems: IF statements with ELSE clauses and
> DO statements:
>					hugh at hcrvx1

I learned this from Dave Ungar while working on the 
Berkeley Smalltalk project.

	# define macro(args)\
		if (1) {\
			/* macro body */\
			/* goes here  */;\
		}\
		else

Notice that the trailing "else" will take care of the ";".  
A macro defined this way can go wherever a legal C statement
can go because this IS a legal C statement (when you call it as
macro(args);).

If you think that "if (1)" is silly and may generate inefficient 
code, you better go find a better compiler.

-- 
			-- Peter Lee
			...{ucbvax!amd,decwrl,ihnp4}!nsc!daisy!pkl

[No news is good news]



More information about the Comp.lang.c mailing list