By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,864 Members | 1,262 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,864 IT Pros & Developers. It's quick & easy.

Unused __VA_ARGS__

P: n/a
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
================================================== ======================
Nov 14 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
REH

"Ian Pilcher" <i.*******@comcast.net> wrote in message
news:A4********************@comcast.com...
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
================================================== ======================


How about another (!) macro for success. For example, if you used "OK":

#define OK ,

TRACE_RETURN(OK);

Nice great, but it may suit your needed.

Nov 14 '05 #2

P: n/a
REH

"REH" <bo***@nowhere.net> wrote in message
news:d1*********@cui1.lmms.lmco.com...
Nice great, but it may suit your needed.

Err, I mean "Not great."

Nov 14 '05 #3

P: n/a
[Some whitespace editing performed in quoting...]

Ian Pilcher wrote:
-> 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).

#define TRACE_RETURN_VOID ...whatever...

return TRACE_RETURN_VOID;

-> 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.

Presumably you still want "foobar returning"?

#define NOTHING
#define VOID NOTHING, ""

return TRACE_RETURN(VOID);
return TRACE_RETURN(NOTHING, "but say something interesting");

--
Peter

Nov 14 '05 #4

P: n/a
in comp.lang.c i read:
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).


seems a horrid replacement given that you wish to, in fact, not trace the
return.

--
a signature
Nov 14 '05 #5

P: n/a
those who know me have no need of my name wrote:

TRACE_RETURN(/* void */, "success");


seems a horrid replacement given that you wish to, in fact, not trace the
return.


Actually, I do want to trace the fact that the function returned. I
just don't have anything else interesting to say. With the original
version of my macro, the above construct would log two lines -- one
that the function is returning, and with "success".

I've since modified the macro to do something like:

#define TRACE_RETURN(rv, ...) \
\
do \
{ \
TRACE("%s returning", __func__); \
TRACE("" __VA_ARGS__); \
return rv; \
} \
while (0)

I modified the underlying logging function to simply output nothing if
the format string is an empty string. Now I can do:

TRACE_RETURN(/* void */, /* success */);

I am restricted to using string literals for the format strings of my
TRACE messages, but it's hard to imagine a situation in which the format
string for a degugging message wouldn't be a literal.

--
================================================== ======================
Ian Pilcher i.*******@comcast.net
================================================== ======================
Nov 14 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.