Pass va_list or pointer to va_list?

前端 未结 6 1127
遇见更好的自我
遇见更好的自我 2020-12-01 12:22

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 i

6条回答
  •  没有蜡笔的小新
    2020-12-01 12:44

    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:

    The object ap may be passed as an argument to another function; if that function invokes the va_arg macro with parameter ap, the value of ap in the calling function is indeterminate and shall be passed to the va_end macro prior to any further reference to ap

    [my italics]

    Edit: Just noticed a footnote in the standard:

    215) It is permitted to create a pointer to a va_list and pass that pointer to another function, in which case the original function may make further use of the original list after the other function returns

    So you can pass a pointer to the va_list and do va_arg(*va_list_pointer) in the called function.

提交回复
热议问题