Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 23rd, 2005, 06:50 AM
jois.de.vivre@gmail.com
Guest
 
Posts: n/a
Default C++ and Anonymous Variadic Macros

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

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles