Suppose I have a.c
and b.c
, which both define types called struct foo
, with different definitions:
#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;
}
#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);
}
In C, can these files both be linked together as part of a standards-conforming program?
(In C++, I believe this is forbidden by the One Definition Rule.)