This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Macro question again
- From: Joe MacDonald <joe at deserted dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 10 May 2002 15:28:33 -0400
- Subject: Macro question again
Hey everyone,
About six months ago I asked almost exactly the same question and got an
answer from John Love-Jensen, (if you're still out there John, thanks!)
but now I'm in a slightly different situation and, while not pressing,
I'd really like to know if anyone has come up with an alternative way to
do this.
I have the following macro:
#define trace(level, format, ...) \
do { \
if (level < debugLevel) \
{ \
fprintf(stderr, "%s:%s:%d> ", __func__, __FILE__, __LINE__); \
fprintf(stderr, format, ##__VA_ARGS__); \
} \
} while(0)
So that I can make calls like:
trace(5, "some trace information = %d\n", anInteger);
Throughout my code. It works fine, but I get a pile of "pasting would
not give a valid preprocessing token" warnings from gcc 2.96 (ugh) and
3.0.1 on my RH 7.0 linux box. John had suggested a bit of a macro-dance
using vfprintf(...) but I'm afraid I haven't been able to arrange the
same functionality without the warnings. Is this approach fundamentally
flawed? Can someone suggest a better (but still C) way to do the same
thing with a macro?
Thanks,
-Joe.
--
Joe MacDonald
:wq