3 ms·
I disagree that this is a fundamental thing. C++ doesn't exactly do "automatic typedef'ing of structures". The difference is that in C++, if you define a type
by _kst_ 3y ago
I disagree that this is a fundamental thing.
C++ doesn't exactly do "automatic typedef'ing of structures".
The difference is that in C++, if you define a type "struct foo", you can refer to it either as "struct foo" or as "foo" (likewise for class, union, and enum).
In C, if you define a type "struct foo", its name is "struct foo". If you want to call it "foo", you have to define an alias using "typedef".
Personally, I see "struct foo" as a perfectly valid name. I seldom feel the need to define another name for it. (typedef is the only way that a C type's name can be a single user-defined identifier; "int", "char" et al are keywords.)
I'll define a typedef for a struct type only if the code that uses it shouldn't know that it's a struct type.
Yes, it's a little extra typing. I save up the keystrokes I save by typing "{" rather than "BEGIN" and use them to type "struct". 8-)}
This is a matter of personal taste, and if you want to call it "foo", there are common idioms for doing that.