preprocessor directives in macros

Henry Spencer henry at utzoo.uucp
Tue Dec 6 05:57:44 AEST 1988


In article <122 at rdahp.UUCP> geoff at rdahp.UUCP (Geoff Walsh) writes:
>#define diagprintf(TestCriteria,TestLevel,Fmt) \
>    #if (TestCriteria >= TestLevel)\
>        printf s\
>    #endif
>
>    1.  Is there any portable, standard way to do something like this with
>        the preprocessor?

Try:

#if TestCriteria >= TestLevel
#define diagprintf(TestCriteria,TestLevel,Fmt) ... /* whatever */
#else
#define diagprintf(TestCriteria,TestLevel,Fmt) 	/* nothing */
#endif

>    2.  Is this legit in ANSI C and do I need to just wait for the
>        next version of my compiler? ...

No.  Putting preprocessor directives inside a macro explicitly does not
work in ANSI C.
-- 
SunOSish, adj:  requiring      |     Henry Spencer at U of Toronto Zoology
32-bit bug numbers.            | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list