[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re[2]: Eliminate Function Call in Conditional Macro
From: |
Shigeru Mabuchi |
Subject: |
Re[2]: Eliminate Function Call in Conditional Macro |
Date: |
Tue, 13 Aug 2002 21:48:58 +0900 |
Hi James,
PORTER, JAMES C (Jim), ALBAS wrote in RE: Eliminate Function Call in
Conditional Macro:
>This is from the IBM Open Class Library, which is trying to do the same
>technique...
>
>#ifdef IC_TRACE_RUNTIME
> #define ITRACE_RUNTIME(p1) ITrace::write(p1)
>#else
> #define ITRACE_RUNTIME(p1)
>#endif
>
>The difference is -- you need to include the parameter in the #define
>variable, so that the parameter is part of the definition.
Yes, but this only works with fixed arguments.
In my Trace function, I use flexible number of arguments,
like printf.
void CProcess::Trace(LPCSTR format, ...)
{
#ifdef _TRACE
va_list args;
va_start(args,format);
..all the printing...
va_end(args);
#endif
}
Although I can filter the printing by including the
above condition inside the Trace function,
a call like
TRACE("info is %d,%d\n",getinfo(x),getinfo(y));
will still do some extra work by calling getinfo().
The easiest way might be to write it as:
#ifdef _TRACE
Trace("info is %d,%d\n",getinfo(x),getinfo(y));
#endif
But this is what I am trying to avoid for better
legibility and less redundancy.
Sorry if I'm asking too much. :-)
Regards,
S. Mabuchi
WING
http://www.wing.gr.jp/