I’m not a beginner, I’m very familiar with the following idiom:
typedef struct Foo_ Foo;// I know typedef struct Foo Foo is fine, I'm just trying to make it clearer
struct Foo_
{
int value;
Foo *link;
};
I’m just suddenly feel confused, because my understanding is that it’s not allowed to use a name(identifier) before it’s declared. But in the declaration typedef struct Foo_ Foo, the identifier Foo_ does not yet exist! How come the compiler permit this happen? Would anybody please shed some light on this, explain to me what’s the justification for this kind of syntax?
Wikipedia quote : The purpose of typedef is to assign alternative names to EXISTING types.
— >8 —
Thank you all guys for so much helpful information.
This is completely fine. The first use of
structtag like yours is a forward declaration of thestructtype.Beware though that your usage of
_Foois not conforming. Identifiers with leading underscore and following capital letter are reserved. Don’t do that. Trailing underscore would be ok.