Reputation: 6926
Does Visual C++ have something similar to __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; }
Upvotes: 1
Views: 863
Reputation: 229058
Not that I know of. But there's no need to use a gcc extension here, use vfprintf instead:
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;
}
Upvotes: 1