Visual C++ 有类似 __builtin_va_arg_pack
的东西吗? ?
This built-in function represents all anonymous arguments of an inline function. It can be used only in inline functions which will be always inlined, never compiled as a separate function, such as those using attribute ((always_inline)) or attribute ((gnu_inline)) extern inline functions. It must be only passed as last argument to some other function with variable arguments. This is useful for writing small wrapper inlines for variable argument functions, when using preprocessor macros is undesirable. For example:
extern int myprintf (FILE *f, const char *format, ...); extern inline __attribute__ ((__gnu_inline__)) int myprintf (FILE *f, const char *format, ...) { int r = fprintf (f, "myprintf: "); if (r < 0) return r; int s = fprintf (f, format, __builtin_va_arg_pack ()); if (s < 0) return s; return r + s; }
最佳答案
据我所知没有。但是这里不需要使用 gcc 扩展,而是使用 vfprintf:
int myprintf (FILE *f, const char *format, ...)
{
va_list ap;
va_start(ap, format);
int r = fprintf (f, "myprintf: ");
if (r < 0)
return r;
int s = vfprintf (f, format, ap);
va_end(ap);
if (s < 0)
return s;
return r + s;
}
关于c - MSVC 有类似 __builtin_va_arg_pack 的东西吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13972329/