Suppose I have a function which takes variadic arguments (...) or a va_list passed from another such function. The main logic is in this function itself (let’s call it f1), but I want to have it pass the va_list to another function (let’s call it f2) which will determine the next argument type, obtain it using va_arg, and properly convert and store it for the caller to use.
Is it sufficient to pass a va_list to f2, or is it necessary to pass a pointer to va_list. Unless va_list is required to be an array type or else store its position data at the location the va_list object points to (rather than in the object itself), I can’t see how passing it by value could allow the calling function (f1) to ‘see’ the changes the called function made by va_arg.
Can anyone shed light on this? I’m interested in what the standard requires, not what some particular implementation allows.
It looks like you’ll need to pass a pointer to the va_list. For more info, see the C99 standard document section 7.15.In particular, bullet point 3 states:
[my italics]
Edit: Just noticed a footnote in the standard:
So you can pass a pointer to the va_list and do
va_arg(*va_list_pointer)in the called function.