Search code examples
cc99c89variadic-functions

Is returning va_list safe in C?


I'd like to write a function that has return type of va_list.

example: va_list MyFunc(va_list args);

is this safe and portable?


Solution

  • va_list might (but is not guaranteed to) be an array type, so you can't pass or return it by value. Code that looks as if it does, might just be passing/returning a pointer to the first element, so you can use the parameter in the callee but you might be acting on the original.

    Formally you can probably say that va_list is an entity type, not a value type. You copy it with va_copy, not with assignment or via function parameters/return.