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

C++ and Anonymous Variadic Macros

P: n/a
Hi,

I'm writing a C++ program that uses C style macros for debugging
purposes. I have code that looks something like this:
#define DEBUG(str, ...) Show(__FILE__, __LINE__, str, ## __VA_ARGS__);

void Show(const char* file, int line, const char* display, ...)
{
char display2[256];
char linestr[10];

va_list va;
va_start(va, display);
vsprintf(display2, display, va);
va_end(va);
sprintf(linestr, "%d", line);

cout << file << " [" << linestr << "]\t" << display2 << endl;
}
This is used in the following manner:

void showNum(int num)
{
DEBUG("The number is %d", num);
}

A sample output would be something like:

show.cpp [35] The number is 15
This is all fine and dandy, but everytime I use this I get the
following warning:

warning: anonymous variadic macros were introduced in C99

Moreover, if I use DEBUG without any additional arguments, for example:

void showHelloWorld()
{
DEBUG("Hello World");
}

I get the following warning in addition to the one above:

warning: ISO C99 requires rest arguments to be used

This appears in every time I use this macro and as a result appears
hundreds of times during compilation. Unfortunately, the warning isn't
very informative, and I'm not sure whether it's one I should heed. If
i'm supposed to ignore it, how can I disable the compiler from
outputting it? In searching for a solution I found that using -std=c99
instead of ansi is supposed to remove this warning, but the -std=c99
option seems to be incompatible with C++.

I'm using GCC 3.4.1 on Suse Linux 9.2

Thanks for any help.

Prashant

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 4 Jul 2005 11:02:29 -0700, jo***********@gmail.com wrote in
comp.lang.c++:
Hi,

I'm writing a C++ program that uses C style macros for debugging
purposes. I have code that looks something like this:
Then your code is using a gcc extension and is really off-topic here.
There are no variadic macros in C++.
#define DEBUG(str, ...) Show(__FILE__, __LINE__, str, ## __VA_ARGS__);
Certainly not C++.
I'm using GCC 3.4.1 on Suse Linux 9.2


If you want help turning off a diagnostic for a non-standard gcc
extension, try the gnu.gcc.* groups or perhaps
news:comp.os.linux.development.apps. It is certainly not a language
issue.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.