c - MSVC 有类似 __builtin_va_arg_pack 的东西吗?

标签 c visual-c++ gcc

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/

相关文章:

c - c 中 _mm_cmpestri 结果的问题

c - 具有可变大小数组的结构

c++ - Visual C++ 类库

c++ - Visual Studio 2015 添加类,错误 : "object already exists"

c - make : 'file' is up to date, 后面什么都不做

c++ - 在 Eclipse IDE 中设置 gcc ( gcc-arm-embedded ) for C/C++ Developers Mars in OS X

c - 如何在 C 中对多维字符数组使用 scanf()

c - 在 C 中包含套接字库时出错

visual-c++ - 将 std::unique_ptr 传递给 CListBox::GetSelItems

assembly - 为什么 GCC 不使用部分寄存器?