I read that in C11 typedef redefinition is allowed, as long as the definitions are the same. However the following code
typedef struct {
int x;
} a_t;
typedef struct {
int x;
} a_t;
int main(int argc, char* argv[]) {
a_t a;
return a.x + argc;
}
when compiled with C11 flag gives me a redefinition error:
% clang -std=c11 -o x x.c
x.c:7:3: error: typedef redefinition with different types ('struct a_t' vs 'struct a_t')
} a_t;
^
x.c:3:3: note: previous definition is here
} a_t;
^
1 error generated.
Interestingly, if the typedef is just a primitive type (i.e. 'typedef int a_t;') then redefinition does not throw error, even without the '-std=c11' flag.
Why can't types with structs be redefined?
This is an issue where definitions coming from 3rd party headers.