J
jois.de.vivre
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
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