Tomáš Zato Tomáš Zato - 1 year ago 120
C Question

Variable arguments without first argument - what belongs in va_start?

I want to make

function for freeing multiple pointers at once, mostly to clean up the code. So I have:

void free_all( ... ) {
va_list arguments;
/* Initializing arguments to store all values after last arg */
// but there are no args!
va_start ( arguments, ????? );
/* we expect the caller to send last argument as NULL **/
void* pointer = va_arg ( arguments, void* );
while( (pointer = va_arg ( arguments, void* ))!=NULL ) {
va_end ( arguments ); // Cleans up the list

So what to put in
va_start ( arguments, ????? )

Answer Source

It's simply not possible. You MUST have a non vararg argument, always. In your case

void free_all(void *first, ...);

could work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download