例如笔者写了一个如下的copy宏
#define IOV_COPY (a, b) \
(a).base = (b).base; \
(a).len = (b).len
如果使用上面的栗子,会发现会出现
‘a’ was not declared in this scope
‘b’ was not declared in this scope
这时我们应当对上面的macro进行修改
#define IOV_COPY(a, b) \
(a).base = (b).base; \
(a).len = (b).len
两个macro的区别仅仅是macro name后面的一个空格
在编写macro时应注意name与param之间没有空格
本文探讨了在C编程中遇到的宏定义错误,具体表现为变量未声明。通过示例展示了宏`IOV_COPY`在使用时出现的错误,并指出问题在于macro名称与参数间不应存在空格。修正后的宏定义确保了正确地拷贝结构体成员,强调了编写宏定义时应注意的细节。
990

被折叠的 条评论
为什么被折叠?



