I have a weird question
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...
DarkEcclipse...
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
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
yea -- we typedef to save typing 6 letters and a space
programmers are lazy bums
programmers are lazy bums
-PoesRaven
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
-Brian
Can''t someone use #define to make an alias for a type?
/. Muzzafarath
/. Muzzafarath
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement