Is it possible to have a variadic function in C with no non-variadic parameter?

Posted by Tim on Stack Overflow See other posts from Stack Overflow or by Tim
Published on 2010-04-12T12:51:05Z Indexed on 2010/04/12 12:53 UTC
Read the original article Hit count: 176

Filed under:
|

I have the following function:

void doStuff(int unusedParameter, ...)
{
    va_list params;
    va_start(params, unusedParameter);
    /* ... */
    va_end(params);
}

As part of a refactor, I'd like to remove the unused parameter without otherwise changing the implementation of the function. As far as I can tell, it's impossible to use va_start when you don't have a last non-variadic parameter to refer to. Is there any way around this?

Background: It is in fact a C++ program, so I could use some operator-overloading magic as suggested here, but I was hoping not to have to change the interface at this point.

The existing function does its work by requiring that the variable argument list be null-terminated, and scanning for the NULL, therefore it doesn't need a leading argument to tell it how many arguments it has.

© Stack Overflow or respective owner

Related posts about c

    Related posts about variadic-functions