【问题标题】:Variadic macros - Comma before the ellipsis?可变参数宏 - 省略号前的逗号?
【发布时间】:2016-05-11 15:52:18
【问题描述】:

我有以下代码:

#define MACRO(x...) x
MACRO(foo,bar)

其中,使用gcc -E,表明MACRO 扩展为foo,bar。但是,C11 标准为类似函数的宏定义了以下语法:

# define identifier lparen identifier-list opt ) replacement-list new-line
# define identifier lparen ... ) replacement-list new-line
# define identifier lparen identifier-list , ... ) replacement-list new-line

似乎没有一个允许x... 位。奇怪的是,上面的 sn-p 扩展为 foo,bar,而 #define MACRO(x, ...) x 正确扩展为 foo。这是一个 gcc 错误,还是我遗漏了什么?

编辑:没关系,这似乎是一个 gcc 扩展,记录在 here

【问题讨论】:

    标签: c macros standards variadic


    【解决方案1】:

    GCC 有自己的规则。省略号前的逗号表示该参数是必需的,没有逗号表示它是可选的。

    【讨论】:

      猜你喜欢
      • 2016-06-12
      • 2014-01-16
      • 2011-04-03
      • 2014-01-24
      • 2011-03-09
      • 2013-04-10
      • 2016-05-14
      • 2020-09-09
      • 2013-06-27
      相关资源
      最近更新 更多