va_copy — porting to visual C++?

前端 未结 4 914
不思量自难忘°
不思量自难忘° 2020-12-15 19:35

A previous question showed a nice way of printing to a string. The answer involved va_copy:

std::string format (const char *fmt, ...);
{
   va_list ap;
   va         


        
4条回答
  •  眼角桃花
    2020-12-15 20:22

    You should be able to get away with just doing a regular assignment:

    va_list apcopy = ap;
    

    It's technically non-portable and undefined behavior, but it will work with most compilers and architectures. In the x86 calling convention, va_lists are just pointers into the stack and are safe to copy.

提交回复
热议问题