Jump to content
  • Advertisement

Archived

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

Estauns

Typedef'ing structs, why don't I understand why? =P

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

Why exactly do people typedef structs? What does it accomplish. You see a lot of: typedef struct struct_t { // Stuff } struct_s What exactly is the point of the typedef?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
it is so that instead of writing

struct struct_t mystruct
you can just write
stuct_s mystruct

I don''t think this is needed in C++ though, just C

Share this post


Link to post
Share on other sites
Really? Then tell my why VC++ 7.1 told me otherwise


struct tagSoundFile
{
ALuint sourceid;
ALuint bufferid;

}SoundFile;

SoundFile test;



Error message

Missing ; before identifier test.

with a typedef, no error.





[edited by - Maega on January 6, 2004 1:48:23 AM]

Share this post


Link to post
Share on other sites
Because SoundFile is an object of that struct, not a type. Try
tagSoundFile test;
or better yet
struct SoundFile
{
// your crap
};
SoundFile test;

typedef is only necessary in classic C.

Share this post


Link to post
Share on other sites
Thats not my point.

I was going by the example put up by the original poster .

If you do use a

struct something
{

}SomethingElse

You do need a typedef to refer to it as SomethingElse.



[edited by - Maega on January 6, 2004 2:04:50 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Maega
If you do use a

struct something
{

}SomethingElse

You do need a typedef to refer to it as SomethingElse.
Again, nope.
struct SomethingElse {};

Share this post


Link to post
Share on other sites
... in that example SomethingElse is an object of a struct - not a struct, so its no surprise that your average compiler has a hard time swallowing it.

[edit]That was a reply to Maega[/edit]

[edited by - emileej on January 6, 2004 2:14:26 AM]

Share this post


Link to post
Share on other sites
I use typedef for really ugly templates:

typedef vector<vector<pair<string,int> > > SomeType;
typedef SomeType::iterator SomeTypeIterator;

Because I don''t want to look at that big thing all the time.

Share this post


Link to post
Share on other sites

  • 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!