__VA_ARGS__

Discussion in 'C Programming' started by Russell Shaw, May 9, 2005.

  1. Russell Shaw

    Russell Shaw Guest

    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, ...)
    {
    ...
    }
     
    Russell Shaw, May 9, 2005
    #1
    1. Advertisements

  2. Russell Shaw

    Russell Shaw Guest

    Disregard, i figured it out. Always have one mandatory parameter
    withing the va-args.
     
    Russell Shaw, May 9, 2005
    #2
    1. Advertisements

  3. #define throw(...) excep_throw(__VA_ARGS__)
     
    William Ahern, May 9, 2005
    #3
  4. Russell Shaw

    James Hess Guest

    Try

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



    -J. Hess
     
    James Hess, May 9, 2005
    #4
  5. Russell Shaw

    Ben Pfaff Guest

    That solution is specific to GCC.
     
    Ben Pfaff, May 9, 2005
    #5
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.