List Info

Thread: DEBUG work for fortune?




DEBUG work for fortune?
country flaguser name
United States
2008-03-21 21:06:29
Can anyone build src/games/fortune with DEBUG? If so, can
you tell me how? 
Thanks.

  Jeremy C. Reed

Re: DEBUG work for fortune?
country flaguser name
United States
2008-03-21 21:14:47
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.

Re: DEBUG work for fortune?
country flaguser name
United States
2008-03-22 00:48:55
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 badlyn"));
   else
           DPRINTF(3, ("still winningn"));

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
dhollandnetbsd.org

Re: DEBUG work for fortune?
country flaguser name
United States
2008-03-22 00:05:34
* Jeremy C. Reed <reedreedmedia.net> [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

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )