假设我有a.c和b.c,它们都定义了被调用的类型struct foo,具有不同的定义:
#include <stdio.h>
struct foo {
int a;
};
int a_func(void) {
struct foo f;
f.a = 4;
printf("%d\n", f.a);
return f.a * 3;
}
Run Code Online (Sandbox Code Playgroud)
#include <stdio.h>
struct foo { // same name, different members
char *p1;
char *p2;
};
void b_func(void) {
struct foo f;
f.p1 = "hello";
f.p2 = "world";
printf("%s %s\n", f.p1, f.p2);
}
Run Code Online (Sandbox Code Playgroud)
在C中,这些文件是否可以作为符合标准的程序的一部分链接在一起?
(在C++中,我认为One Definition Rule禁止这样做.)