Disappearing function call

mcg at omepd.UUCP mcg at omepd.UUCP
Mon Oct 13 08:22:57 AEST 1986

You guys are all thinking too hard.  Even the venerable Chris Torek has
proposed a solution more complex than needed.  On any compiler likely to
be used for production code, the optimizer will generate no code
whatsoever for the following fragment:

	#define DEBUG	0	/* set to 1 to turn debugging on */


	if (DEBUG) debug(...);

Similarly, in the case of '#define DEBUG 1', the unneccesary test will
be elided.
In the idiom of the original posting, the example is:

	#define	debug	if(DEBUG) debug


Though care must be taken in using this form in un-braced if statements
that have else clauses.

The preprocessor solutions have the intoxicating air of complexity about
them, but, in my experience, this solution proves easiest and most
effective.  Why look for trouble?  Trouble will find you.

S. McGeady

More information about the Comp.lang.c mailing list