Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable arguments without first argument - what belongs in va_start?

I want to make varargs 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 ) {
        free(pointer);
    }
    va_end ( arguments );                  // Cleans up the list
}

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

like image 416
Tomáš Zato - Reinstate Monica Avatar asked Nov 28 '16 14:11

Tomáš Zato - Reinstate Monica


1 Answers

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

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

could work.

like image 148
Iharob Al Asimi Avatar answered Sep 20 '22 11:09

Iharob Al Asimi