Connecting Tech Pros Worldwide Help | Site Map

C++ and Anonymous Variadic Macros

  #1  
Old July 23rd, 2005, 06:50 AM
jois.de.vivre@gmail.com
Guest
 
Posts: 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

  #2  
Old July 23rd, 2005, 06:50 AM
Jack Klein
Guest
 
Posts: n/a

re: C++ and Anonymous Variadic Macros


On 4 Jul 2005 11:02:29 -0700, jois.de.vivre@gmail.com wrote in
comp.lang.c++:
[color=blue]
> Hi,
>
> I'm writing a C++ program that uses C style macros for debugging
> purposes. I have code that looks something like this:[/color]

Then your code is using a gcc extension and is really off-topic here.
There are no variadic macros in C++.
[color=blue]
> #define DEBUG(str, ...) Show(__FILE__, __LINE__, str, ## __VA_ARGS__);[/color]

Certainly not C++.
[color=blue]
> I'm using GCC 3.4.1 on Suse Linux 9.2[/color]

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
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why C Is Not My Favourite Programming Language evolnet.regular@gmail.com answers 134 November 14th, 2005 07:25 PM
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit answers 0 November 13th, 2005 06:45 PM
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit answers 0 November 13th, 2005 05:26 PM
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit answers 0 November 13th, 2005 03:16 AM