I am trying to create a macro which can be used in place of a return
statement to (optionally) log a function's result. My initial version
was:
#define TRACE_RETURN(rv, ...) \
\
do \
{ \
TRACE("%s returning", __func__); \
TRACE(__VA_ARGS__); \
return rv; \
} \
while (0)
For example,
return rv;
would be replaced by
TRACE_RETURN(rv, "returning %d", rv);
Similarly,
return;
is replaced by
TRACE_RETURN(/* void */, "success");
This works, but I'd like to get rid of the "success" or similar
redundant string (which causes a line of useless output in my log file).
I had the bright(?) idea of modifying my logging function to simply
suppress all output if the format string is blank, and I redefined the
TRACE_RETURN macro as follows:
#define TRACE_RETURN(rv, ...) \
\
do \
{ \
TRACE("%s returning", __func__); \
TRACE("" __VA_ARGS__); \
return rv; \
} \
while (0)
The idea is to be able to do:
TRACE_RETURN();
or
TRACE_RETURN(0);
when there's nothing interesting to log.
Unfortunately, this causes my compiler (GCC 3.4.2) to complain about the
variable arguments not being used. I can get rid of the warning/error
by using
TRACE_RETURN(,);
but this is arguably uglier than what I'm trying to get rid of.
Any ideas?
Thanks!
--
================================================== ======================
Ian Pilcher i.*******@comcast.net
================================================== ======================