🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9663

Re: Disappearing function call

#9663
From: andy
Date: Tue, 28 Oct 1986 08:11
31 lines
1636 bytes
#define	DEBUG	1 /* or 0 as appropriate */

#define	debug	if( DEBUG ) fprintf

(Replace fprintf with the appropriate function.)

Then you can write:
    debug( stderr, "wrong args %d, %s, %p\n", d, s, p ); /* %p is bogus */

Either your compiler eliminates dead code or it doesn't.
If it doesn't, other dead code and missed opportunities to generate
good code will swamp the overhead of checking if 0 is still 0 and
skipping the fprintf.  If it does, the fprintf (and its args) will be
removed.

-andy

ps - Yes, I know my debug will pick up a following "else".  I use "extra"
{}'s and debug( <args> ) shouldn't be followed by an "else" anyway; I'll
document that feature and let it slide.  It is difficult to handle all
possible constraints with something as limited as cpp; "debug( (<args>) )"
grates on me.

I'd rather write "if( DEBUG ) <code>" directly than "debug( <args> )"
because it doesn't restrict <code>.
-- 
Andy Freeman
UUCP:  ...!decwrl!shasta!andy forwards to
ARPA:  andy@sushi.stanford.edu
(415) 329-1718/723-3088 home/cubicle
Technical Details
Message-ID: <947@Shasta.STANFORD.EDU>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!think!mit-eddie!genrad!decvax!decwrl!labrea!Shasta!andy
References: <357@cullvax.UUCP> <162@omepd> <2865@rsch.WISC.EDU>

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!think!mit-eddie!genrad!decvax!decwrl!labrea!Shasta!andy
From: andy@Shasta.UUCP
Newsgroups: net.lang.c
Subject: Re: Disappearing function call
Message-ID: <947@Shasta.STANFORD.EDU>
Date: Tue, 28-Oct-86 03:11:23 EST
Article-I.D.: Shasta.947
Posted: Tue Oct 28 03:11:23 1986
Date-Received: Tue, 28-Oct-86 21:17:36 EST
References: <357@cullvax.UUCP> <162@omepd> <2865@rsch.WISC.EDU>
Reply-To: andy@Shasta.UUCP (Andy Freeman)
Organization: Stanford University
Lines: 31