473,414 Members | 1,677 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,414 software developers and data experts.

__VA_ARGS__

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:

error: parse error before ')' token
I think it's because without the last parameter, the function is
called as: except_throw("Error", ). How do i get rid of this trailing
comma problem?

I'm using gcc-3.4.4.
void excep_throw(char *msg, ...)
{
...
}
Nov 14 '05 #1
4 10735
Russell Shaw wrote:
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:

error: parse error before ')' token
I think it's because without the last parameter, the function is
called as: except_throw("Error", ). How do i get rid of this trailing
comma problem?

I'm using gcc-3.4.4.
void excep_throw(char *msg, ...)
{
...
}


Disregard, i figured it out. Always have one mandatory parameter
withing the va-args.
Nov 14 '05 #2
Russell Shaw <rjshawN_o@s_pam.netspace.net.au> wrote:
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:

error: parse error before ')' token
I think it's because without the last parameter, the function is
called as: except_throw("Error", ). How do i get rid of this trailing
comma problem?


#define throw(...) excep_throw(__VA_ARGS__)

Nov 14 '05 #3

Russell Shaw wrote:
Hi,

I have a variadic macro:

#define throw(msg, ...) excep_throw(msg, __VA_ARGS__)


Try

#define throw(msg, ...) excep_throw(msg, ##__VA_ARGS__)

-J. Hess

Nov 14 '05 #4
"James Hess" <my*****@gmail.com> writes:
Russell Shaw wrote:
I have a variadic macro:

#define throw(msg, ...) excep_throw(msg, __VA_ARGS__)


Try

#define throw(msg, ...) excep_throw(msg, ##__VA_ARGS__)


That solution is specific to GCC.
--
"...deficient support can be a virtue.
It keeps the amateurs off."
--Bjarne Stroustrup
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
5
by: jake1138 | last post by:
I couldn't find an example of this anywhere so I post it in the hope that someone finds it useful. I believe this is compiler specific (I'm using gcc), as C99 defines __VA_ARGS__. Comments are...
5
by: Ian Pilcher | last post by:
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, ...) ...
3
by: Thomas Carter | last post by:
I understand that C99 supports variadic macros. However, is it not the case that a variadic macro defined as #define SAMPLE_MACRO(...) Bloody-blah must take at least one argument? I would be...
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...
12
by: Laurent Deniau | last post by:
I was playing a bit with the preprocessor of gcc (4.1.1). The following macros expand to: #define A(...) __VA_ARGS__ #define B(x,...) __VA_ARGS__ A() -nothing, *no warning* A(x) -x ...
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...
28
by: ravi | last post by:
Hello everybody, I am writing a small application which does some work before the user main function starts execution. I am trying to #define the main function. But the problem is that,
8
by: Christof Warlich | last post by:
Hi, is there any way to access individual elements in the body of a variadic macro? I only found __VA_ARGS__, which always expands to the complete list. Thanks for any help, Christof
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.