Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
You need the first one if you have references to that type in the type itself - e.g. for prev/next pointers in linked lists. That's because the new type definition is only visible after the end of the statement.
Also, you can give the same "Name" in both places. -
@Fast-Nop Ah, I didn't know that. I learned that from the Windows API which does the underscore deal. Maybe left over from an old compiler? I know Windows supports backwards compatibility religiously
-
@AlgoRythm That's so that you can refer to the type either using the struct _Name or just Name method. Maybe if you have these self-referential declarations for linked lists, some people like to point out what exactly they are referring to, the struct or the resulting type. I guess it's a matter of taste.
-
CurtisMJ4605yOne of the reasons I had found for actually naming structs is that you can't forward declare an anonymous struct(which is kind of obvious now I think about it) if for example you want to hide implementation details, even if you typedef it. Most of the time I just name things like
typedef struct name_s {} name_t;
Honestly there's not much reason not to name a struct.

typedef struct _Name {
} Name;
Or
typedef struct {
} Name;
...and why?
question