Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: preprocessor directives in macros Message-ID: <1988Dec5.195744.3797@utzoo.uucp> Organization: U of Toronto Zoology References: <122@rdahp.UUCP> Date: Mon, 5 Dec 88 19:57:44 GMT In article <122@rdahp.UUCP> geoff@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@zoo.toronto.edu