#define MyStruct(T) struct {T data;}
void foo(MyStruct(int) s);
void foo(MyStruct(int) s) {
return;
}
int main(void) {
//...
return 0;
}
这会导致错误:
main.c:7:6: error: conflicting types for 'foo'
void foo(MyStruct(int) s) {
^
main.c:5:6: note: previous declaration is here
void foo(MyStruct(int) s);
^
如果我创建一个 typedef,例如typedef MyStruct(int) MyIntStruct;
并使用它,则没有错误。
所以我的问题是,为什么会出现冲突类型错误?是否所有匿名结构都是唯一的,例如编译器无法确定它们是否是完全相同的类型?