__VA_ARGS__

R

Russell Shaw

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, ...)
{
...
}
 
R

Russell Shaw

Russell said:
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.
 
W

William Ahern

Russell Shaw said:
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__)
 
J

James Hess

Russell said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top