Nested Macros

Yuval Yarom yval at tasu23.UUCP
Tue Nov 21 18:49:31 AEST 1989


In article <gZO1Sce00W0JQ6AKEr at andrew.cmu.edu> jb3o+ at andrew.cmu.edu (Jon Allen Boone) writes:
>A friend is attempting to write a macro along the following lines:
>
>#define DEBUG 1
>
>#define DB(X) #ifdef (DEBUG) printf(X)
>
>however, this results in an error when he attempts to compile it.
>
>does anyone know how he would go about writing a macro that would
>allow him to simply type DB(x) in his code and not have to type #ifdef
>(DEBUG) printf(X) everywhere instead? Any help would be greatly
>appreciated.  Please carbon copy your reply to pg0p at andrew.cmu.edu, as
>well as to jb3o at andrew.cmu.edu and the board.
>
>thank you...

He should use:

#define DEBUG 1

#ifdef DEBUG
#define DB(X) printf(X)
#else
#define DB(X) /* */
#endif

--
Yuval Yarom
yval%taux01 at nsc.nsc.com



More information about the Comp.lang.c mailing list