Jump to content
  • Advertisement

Archived

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

DarkEcclipse

I have a weird question

This topic is 6696 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''ve noticed that some of the stuff you guys do with ''struct'' you guys add ''typedef''... I''m a little confused about what it is and does. I think it means "type definition" but I''m not sure. Please help! DarkEcclipse...

Share this post


Link to post
Share on other sites
Advertisement
First off, there are no wierd questions, just wierd people...

Actually, typedef isn't needed, but it just saves typing struct later on. Exp:

struct stuff {
int numb;
char text[80];
};

struct stuff info;


hence you have to type "struct stuff" everytime you want to create that structure. However:

typedef struct stuff {
int numb;
char text[80];
} Fast;

Fast info;


is all you do. As you can see, you only type one word to declare a structure of "stuff", and its slightly easier to read, also.

As for what it does, it simply alows you to add new keywords that have existing keyword functionality. for example:

int i = 0;
int j = 9;
int y = -65;


ok, but typdef allows you to custumize your keywords:

typedef int CoolNumbers;
CoolNumbers i = 0;
CoolNumbers j = 9;
CoolNumbers y = -65


These two code segments are identical.

Edited by - Zipster on 4/13/00 9:26:04 PM

Share this post


Link to post
Share on other sites
This is true, but ONLY in C. In C++, typedef is NOT needed for struct''s. (Because, as I have pointed out elsewhere, struct == class in C++.) Typedef still has uses though, as it''s primary purpose is to add aliases for types. (Just not for structures)

-Brian

Share this post


Link to post
Share on other sites
you CAN use defines for that purpose, but that is really a very lame way. use typedef and you'll be on the safer side

Edited by - Ridcully on 4/14/00 4:17:05 AM

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!