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, ????? )
?
It's simply not possible. You MUST have a non vararg argument, always. In your case
void free_all(void *first, ...);
could work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With