Jump to content
  • Advertisement
Sign in to follow this  
beebs1

C++ Structures

This topic is 3884 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

Hiya, I have a quick question I was hoping someone could answer - what's the difference between these two structure declarations?
struct MYSTRUCT
{
   int a;
};

struct
{
   int a;
} MYSTRUCT;
Thanks for any help - I've always assumed they are the same, but thought I'd check! [smile]

Share this post


Link to post
Share on other sites
Advertisement
The first defines a structure named MYSTRUCT.

The second defines a variable named MYSTRUCT of an unnamed structure type.

Share this post


Link to post
Share on other sites
Often in C you will see code like this:

typedef struct Foo {
int a;
} Foo;



This doesn't declare any variables, it just allows one to reference a structure without dealing with the structure "namespace".

Example:

struct One { int a; };

void frobnicate( struct One * );
// void frobnicate( One * ); causes error


Versus:


typedef struct One { int a; } One;

// void frobnicate( struct One * ); could still do this
void frobnicate( One * ); // easier to read

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!