tech-misc archive

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

Re: DEBUG work for fortune?



* 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


Home | Main Index | Thread Index | Old Index