当所有参数都传递给 HTML_A 时,此代码按预期工作:
#include <stdio.h>
#define HTML_A_fmt_void
#define HTML_A_arg_void
#define HTML_A_fmt_link(fmt, ...) " href=\""fmt"\""
#define HTML_A_arg_link(fmt, ...) ,__VA_ARGS__
#define HTML_A_fmt_text(fmt, ...) fmt
#define HTML_A_arg_text(fmt, ...) ,__VA_ARGS__
#define HTML_A(link, text) \
printf("<a" HTML_A_fmt_##link ">" HTML_A_fmt_##text "</a>\n" HTML_A_arg_##link HTML_A_arg_##text)
int main(void)
{
HTML_A(
link("%s", "http://wwww.google.com"),
text("%s", "Visit google")
);
HTML_A(
link("%s", "http://wwww.google.com"),
void
);
HTML_A(
void,
text("%s", "Visit google")
);
HTML_A(
void,
void
);
return 0;
}
但是,如果我想以格式调用不带参数的 HTML_A:
HTML_A(
link("http://wwww.google.com"),
text("Visit google")
);
我在 gcc 下收到此编译错误:
demo.c:17:1:警告:ISO C99 需要使用其他参数
demo.c:在函数“main”中:
demo.c:17:错误:“,”标记之前的预期表达式
cpp 返回:
printf("<a" " href=\"""http://wwww.google.com""\"" ">" "Visit google" "</a>\n" , ,);
与,,
在最后。