-
|
Why is it in C, do you need to be so verbose in writing out the definition of structs? typedef struct V2
{
int X;
int Y;
} V2; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
This has to do the the differences between C++ and C. C++ wanted to do away with 'ceremonial' type stuff like this. In C, the struct definition and type tags are treated separately. Struct only defines a struct tag. This has to be used explicitly in each reference unless you also add a typedef. It is also now, a little too late. Since, if C were to modernize and remove this verbosity, it could now break a bunch of old C code that uses this verbose syntax. |
Beta Was this translation helpful? Give feedback.
This has to do the the differences between C++ and C. C++ wanted to do away with 'ceremonial' type stuff like this.
In C, the struct definition and type tags are treated separately. Struct only defines a struct tag. This has to be used explicitly in each reference unless you also add a typedef.
It is also now, a little too late. Since, if C were to modernize and remove this verbosity, it could now break a bunch of old C code that uses this verbose syntax.
Imagine some C code referencing struct V2 everywhere in the codebase. So, this was kept to keep new C standards backwards compatible.