I have the following declaration in a header file:
struct my_struct;
int func(struct my_struct* s); // Passing struct my_struct*
Without the forward declaration, the compiler would obviously give this error:
error: 'struct my_struct' declared inside parameter list
However, if I replace the forward declaration of my_struct with a typedef, and update the function declaration accordingly, it compiles fine:
typedef struct my_struct my_struct_t;
int func(mystruct_t* s); // Passing my_struct_t*
Curiously, if I keep the typedef, but use the original declaration my_struct, it also compiles:
typedef struct my_struct my_struct_t;
int func(struct my_struct* s); // Passing struct my_struct*
Did anybody else notice that? Is that behavior a side-effect?
In section 6.2.1, paragraph 7:
And in 6.7.2.3, paragraph 8:
The
typedefthus declares an incomplete structure type.