|
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; |
Answered by
bagaffey
Sep 11, 2025
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. |
0 replies
Answer selected by
btgvesta
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to 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.
Imagine some C code referencing struct V2 everywhere in the codebase. So, this was kept to keep new C standards backwards compatible.