Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!ukma!rutgers!okstate!garnett
From: garnett@a.cs.okstate.edu (John Garnett)
Newsgroups: comp.lang.c
Subject: Re: preprocessor directives in macros
Message-ID: <4223@okstate.UUCP>
Date: 4 Dec 88 23:19:55 GMT
References: <122@rdahp.UUCP>
Distribution: na
Organization: Oklahoma State Univ., Stillwater
Lines: 32

From article <122@rdahp.UUCP>, by geoff@rdahp.UUCP (Geoff Walsh):
> 
> I tried to use the preprocessor with something like:
> 
> #define diagprintf(TestCriteria,TestLevel,Fmt) \
>     #if (TestCriteria >= TestLevel)\
>         printf s\
>     #endif
> 
> to get the preprocessor to eliminate dead code AND the strings associated
> with Fmt, but the compiler didn't like this.  I get an error message
> like "Expected formal macro parameter" with one compiler, and " # operator

How about using something like the following:

#ifdef DEBUG
#define diagprintf(TestCriteria,TestLevel,Fmt) \
	if (TestCriteria >= TestLevel) {printf Fmt; fflush(stdout); }
#else
#define diagprintf(TestCriteria,TestLevel,Fmt)
#endif

Then you can control whether or not the debug code is even compiled
by using 'cc -DDEBUG code.c' to include debug code or 'cc code.c'
to prevent the code from being sent to the compiler.

John Garnett


~ John Garnett                         Internet: garnett@a.cs.okstate.edu
~ Computing and Information Sciences   UUCP: {cbosgd, ihnp4, rutgers}!
~ Oklahoma State University                   okstate!garnett