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: Alfred Perlstein <bright%mu.org@localhost>

Date: Fri, 21 Mar 2008 22:05:34 -0700


* Jeremy C. Reed <reed%reedmedia.net@localhost> [080321 20:25] 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.)
> 
> 
>  # ifdef DEBUG
> -# define     DPRINTF(l,x)    if (Debug >= l) fprintf x; else
> +# define     DPRINTF(l,x)    if (Debug >= l) fprintf x;
>  # undef              NDEBUG
>  # else
>  # define     DPRINTF(l,x)
> 
> 
> As I don't understand why that "else" is there, I didn't commit the above.

A better fix would be to code DPRINTF() as such:

# define DPRINTF(l,x)    \
do { if (Debug >= l) fprintf x; } while (0)

The reason for the empty else is to prevent the debug code
from causing ambiguous if constructs in the code.

The do-while(0) wraper will fix that.

-- 
- Alfred Perlstein


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: du -m is off

Previous by Thread: Re: DEBUG work for fortune?

Next by Thread: du -m is off

Indexes:

reverse Date

reverse Thread

Old Index



Home | Main Index | Thread Index | Old Index