🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9461

Re: Disappearing function call

#9461
From: Frank Whaley
Date: Thu, 02 Oct 1986 17:21
48 lines
1770 bytes
In article <357@cullvax.UUCP> drw@cullvax.UUCP (Dale Worley) writes:
>What I want to do is to write a function call of a variable number of
>arguments:
>	debug(x, y, z, ...)
>that will generate no code when the symbol DEBUG is not defined, but
>generate a call of some function (say, debug_()) when it is.

Numerous ugly examples deleted.

I had to do this just recently, and took advantage of the fact that my
compilers "optimize out" code like this:

	if (0) function();

So assuming:

	#ifdef	DEBUG
	#define	_DEBUG	1
	extern void _debug(char *,)	/*  debugging printf()  */
	#else
	#define	_DEBUG	0
	#endif
	#define	debug	if(_DEBUG)_debug

a statment like:

	debug("%d:%d:%d\n", a, b, c);

becomes either:

	if(1)_debug("%d:%d:%d\n", a, b, c);
or
	if(0)_debug("%d:%d:%d\n", a, b, c);	/*  no code generated  */

All of my compilers generate the strings anyway, so I used a set of external
strings (bracketed by #ifdef's) for all debugging messages.  Some compilers
require an optimizer pass to eat the dead code.

-- 
Frank Whaley
Senior Engineer, Beyond Words
UUCP:		hplabs!
	   ihnp4!ptsfa!
	seismo!lll-crg!well!few
ARPA:	well!few@lll-crg.ARPA

Water separates the people of the world;
wine unites them.
Technical Details
Message-ID: <1876@well.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-crg!lll-lcc!well!few
References: <357@cullvax.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-crg!lll-lcc!well!few
From: few@well.UUCP (Frank Whaley)
Newsgroups: net.lang.c
Subject: Re: Disappearing function call
Message-ID: <1876@well.UUCP>
Date: Thu, 2-Oct-86 13:21:46 EDT
Article-I.D.: well.1876
Posted: Thu Oct  2 13:21:46 1986
Date-Received: Sat, 4-Oct-86 06:40:18 EDT
References: <357@cullvax.UUCP>
Reply-To: few@well.UUCP (Frank Whaley)
Organization: Whole Earth Lectronic Link, Sausalito CA
Lines: 48