473,411 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Unused __VA_ARGS__

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
5 6043
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
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
[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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Brad Tobin | last post by:
On a production database, there is a 2GB database, when I run sp_spaceused it indicates a very high quanity of unused space. The database has been shrunk & free space sent to the OS. Why is this...
15
by: Eirik | last post by:
This is a little function I wrote, inspired by the thread "Urgent HELP! required for Caesar Cipher PLEASE" $ cat /home/keisar/bin/c/ymse/rot13.h char rot13(char character) { int changed;...
11
by: Michael B Allen | last post by:
Is there a standard method for supressing warnings regarding unused parameters? I have a function that might be called hundreds of thousands of times that looks like this: const void *...
4
by: Russell Shaw | last post by:
Hi, I have a variadic macro: #define throw(msg, ...) excep_throw(msg, __VA_ARGS__) If i do: throw("Error", 0), it compiles ok. If i do: throw("Error"), i get an error:
12
by: zacks | last post by:
Suddenly, in a VB2005 project I am working on, several variables show up in the list of warnings are being unused local variables. But they all are. Several of them are the ex variable used in a...
15
by: Urs Thuermann | last post by:
I want to write a macro that produces debug output and has a variable number of arguments, so that I can use like this: int i; char *s; DBG("simple message\n"); DBG("message with an int...
2
by: kailasn | last post by:
I am getting compiler error : error C2065: '__VA_ARGS__' : undeclared identifier I am using Microsoft Visual Stodio 6.0. Also I cant see this macro to be defined in ant of standard header...
33
by: jacob navia | last post by:
Hi I am considering extending the lcc-win32 compiler to accept int fn(int a, int b,double) { // body of the function } This allows the programmer to specify that the third parameter is not...
13
by: Rex Mottram | last post by:
I'm using an API which does a lot of callbacks. In classic callback style, each routine provides a void * pointer to carry user-defined data. Sometimes, however, the user-defined pointer is not...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.