Archived

This topic is now archived and is closed to further replies.

Brobanx

C specific

Recommended Posts

Brobanx    136
  
typedef struct
{
   int somevar;
} mystruct;

typedef struct mystruct
{
   int somevar;
};
  
What is the difference between these two forms of declaring a struct?

Share this post


Link to post
Share on other sites
jenova    122
the first one creates a "type definition" and the second creates a "struct definition".

the first allows you to define....

mystruct ms;

but not....

struct mystruct ms;


the second allows you to define....

struct mystruct ms;

but not....

mystruct ms;


there will be no performance difference. if you don''t mind typing "struct" in front of declarations/definitions.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

Share this post


Link to post
Share on other sites
jenova    122
tho, if you want to do the following then you will have to use the "struct definition".


struct MYSTRUCT {
struct MYSTRUCT *next;
};

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

Share this post


Link to post
Share on other sites
ekenslow    122
You can mix em too:

typedef struct tagMyStruct {
struct tagMyStruct* pNext;
} MYSTRUCT;

After this, struct tagMyStruct and MYSTRUCT are identical types.

--
Eric

Share this post


Link to post
Share on other sites