tech-misc archive

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

Re: DEBUG work for fortune?



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


Home | Main Index | Thread Index | Old Index