【发布时间】:2015-07-11 06:52:49
【问题描述】:
我需要做类似的事情:
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#define INCR(count,ARGS...) \
if(ARGS) \
count++; \
void main()
{
int count =1;
int flag =1;
INCR(count);
printf("count %d",count);
INCR(count,flag); /* flag determines if the count is to be incremented or not */
printf("count %d",count);
}
我收到以下错误:
sh-4.3$ gcc -o main*.c main.c:在函数'main'中: main.c:6:8: 错误: ')' 标记之前的预期表达式 如果(ARGS)\ ^ main.c:15:5:注意:在宏“INCR”的扩展中 增量(计数); ^ sh-4.3$这里的计数器应该只在标志存在时才增加。我需要一个参数数量灵活的宏。请帮我解决这个问题
【问题讨论】:
-
请记住,行尾的`\`字符是行继续字符,表示当前行将与下一行连接为单行.
-
另外我怀疑你想用可执行程序覆盖源文件,所以我建议你在 actual 程序的
-o之后添加一个额外的参数 gogcc. -
您希望
INCR(count)的预处理代码是什么样的? -
了解这个要求就好了
-
顺便说一句,this variadic macro reference 可能会有所帮助。