c - C 中的嵌套宏

标签 c

#include<stdio.h>
#define A(int x) printf("%d\n",x)
#define AS(A) A(20)
typedef struct{
 int *m;
 int n;
 int k;
}st;
//static st sb[10] = {AS(A)}
int main()
{
    AS(A);
    return 0;
}

我收到如下错误。

Line 14: error: macro parameters must be comma-separated

请帮忙。

最佳答案

这与嵌套宏无关。问题是

#define A(int x) printf("%d\n",x)

您必须删除 int 部分。像这样:

#define A(x) printf("%d\n",x)

如果您保留 int,预处理器会将其解释为另一个参数,这就是它告诉您的原因

Line 14: error: macro parameters must be comma-separated

因为期望:

#define A(int,x) printf("%d\n",x)

关于c - C 中的嵌套宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8064151/

相关文章:

c - 从函数到主函数使用字符串

c++ - 生成字典排列 : Segmentation fault

c - 如何用指向存储在另一个数组中的字符串的指针填充字符指针数组?

c - C 中的结构中的字符串

c - 为什么这段代码在输入和输出行之间打印一个随机字符?

c - 尝试理解定义文件类型的宏

c - 如何抑制 int main(void) 函数的 PC-Lint Note 970?

c - 用户提示再次播放不起作用

c - c中修饰符static的使用

c - 如何在 MS-windows vista 中使控制台屏幕(Turbo C 编辑器)全屏显示