Nested Macros

D'Arcy Cain darcy at bbm.UUCP
Thu Nov 23 08:15:13 AEST 1989


In article <gZO1Sce00W0JQ6AKEr at andrew.cmu.edu> 
jb3o+ at andrew.cmu.edu (Jon Allen Boone) writes:
>#define DEBUG 1
>
>#define DB(X) #ifdef (DEBUG) printf(X)
>

I would have coded the above  as follows just because I don't like
smart-alecky code (or more accurately I'm afraid some compiler won't :-).)

#ifdef DEBUG
#define DB(X) printf(X)
#else
#define DB(X)

This however still has the problem that printf has a variable number of
arguments so you  have to call it like this:

    DB(("Error: Result code is %d\n", res));   /* note double parentheses */

and that is probably your error.

D'Arcy



More information about the Comp.lang.c mailing list