Create va_list dynamically

后端 未结 7 749
一个人的身影
一个人的身影 2020-12-06 01:08

I have a function

void foo(int cnt, va_list ap);

I need to use it, but requirement is quite strict, number of va_list vary an

7条回答
  •  我在风中等你
    2020-12-06 01:44

    Your question is tagged C++ and there are nice ways (like streams) to avoid varargs completely in C++.

    This is a great example of why va_args can cause pain. If you have any chance at all to change the signature of foo, that's your best option. Taking a std::vector instead of va_list would just solve your problem right there.

    If foo is in an external library you can't change, my next suggestion would be to find a different library.

    If none of those is an option it seems like there ought to be a way to recursively build up the call list using va_list, but I couldn't figure out how to make that work.

提交回复
热议问题