Re: DEBUG work for fortune?

David Holland <[email protected]>
Newsgroups gmane.os.netbsd.devel.general
Message-ID <[email protected]>
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
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.