Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Declaring a Struct in C: Why do I have to Specify the Name Twice?

In order to declare a struct in C, I have been using

typedef struct Foo Foo;

and then defining it at some point below.

Why do I have to specify the name of the struct (Foo) twice?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The format is

typedef old_type new_type

so for

typedef struct Foo Foo;

struct Foo is the old type and Foo is the new type, so whenever you type Foo it is really an alias for struct Foo.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading