Jump to content
  • Advertisement
Sign in to follow this  
v0dKA

Defining structs

This topic is 4954 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have seen two ways of defining structs. One way is:
struct Struct_Name
{
     int a, b, c ...;
};
And here's another method I've seen:
struct Some_weird_name_here
{
     int a, b, c ...;
} Struct_Name;
What is the point of the second method? I've seen it used in a lot of places, from online artices to winuser.h. But what exactly is the purpose of using that method?

Share this post


Link to post
Share on other sites
Advertisement
The latter is equivalent to

struct Some_weird_name_here
{

int a, b, c ...;
};

struct Some_weird_name_here Struct_Name;

That is, it defines the struct and creates an instance of it.

You may also have come across something like

typedef struct Some_weird_name_here
{

int a, b, c ...;
} Struct_Name;

This is because in C (not in C++, though!), Some_weird_name_here alone is not a fully qualified name for the struct (you need to prefix it with the keyword struct, as I did in the previous example); with the aid of a typedef, you can simply use the typedef-ed name, instead. This is thus equivalent to


struct Some_weird_name_here
{

int a, b, c ...;
};

typedef Some_weird_name_here Struct_Name;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!