tech-misc archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: DEBUG work for fortune?




To: "Jeremy C. Reed" <reed%reedmedia.net@localhost>

Subject: Re: DEBUG work for fortune?

From: David Holland <dholland-tech%netbsd.org@localhost>

Date: Sat, 22 Mar 2008 05:48:55 +0000


On Fri, Mar 21, 2008 at 09:14:47PM -0500, Jeremy C. Reed wrote:
 > Here is my error:
 > 
 > fortune.c:544: warning: empty body in an else-statement
 > (repeated many times)
 > 
 > Here is the code (gcc with -E to preprocess only):
 > 
 > if (Debug >= 1) fprintf ((&__sF[2]), "adding file \"%s\"\n", path); else;
 > 
 > 
 > What is the purpose of the following "else;" which I removed so I could 
 > compile with debugging? (It is from pre-NetBSD code.)
 > [...]
 > -# define    DPRINTF(l,x)    if (Debug >= l) fprintf x; else
 > +# define    DPRINTF(l,x)    if (Debug >= l) fprintf x;

It is probably so code like

   if (lose)
           DPRINTF(3, ("losing badly\n"));
   else
           DPRINTF(3, ("still winning\n"));

doesn't expand to the wrong thing.

It is probably better replaced with something like

#define DPRINTF(l,x) (Debug >= (l) ? fprintf x : (void)0)

or the do { } while (0); form.

It might also be nice to change it to a varargs macro, but that would
require removing the extra parens from all the call sites.

-- 
David A. Holland
dholland%netbsd.org@localhost


References:

DEBUG work for fortune?
From: Jeremy C. Reed

Re: DEBUG work for fortune?
From: Jeremy C. Reed




Prev by Date: Re: DEBUG work for fortune?

Next by Date: Re: DEBUG work for fortune?

Previous by Thread: Re: DEBUG work for fortune?

Next by Thread: Re: DEBUG work for fortune?

Indexes:

reverse Date

reverse Thread

Old Index



Home | Main Index | Thread Index | Old Index