|
-
Jan 11th, 2002, 08:15 PM
#1
Thread Starter
Fanatic Member
Struct/typedefs
I have seen code like this in some places:
Code:
typedef struct _mystruct {
int x;
int y;
} mystruct;
But, in my C++ class at school, the teacher told us to do it like this (no typedef):
Code:
struct mystruct {
int x;
int y;
};
Why would you do the first one if the second one works?
Alcohol & calculus don't mix.
Never drink & derive.
-
Jan 11th, 2002, 10:43 PM
#2
In C, if you used:
Code:
struct <name> { // stuff };
You would have to declare variables of <name> like so:
Code:
struct <name> myVar;
When using the typedef, you eliminate the extra struct.
Z.
-
Jan 12th, 2002, 06:28 AM
#3
In C++, this weird syntax is no longer necessary. So it is absolutely understandable if your teacher tells you not to do it (it still works). But he should have told you why they did it otherwise in C.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|