-
Is there any difference?
Is there any difference in a typedef struct and a normal struct? This works just as expected either way:
Code:
#include <iostream>
using namespace std;
typedef struct {
int x, y;
} Point;
struct Point2 {
int x, y;
};
int main() {
Point p;
Point2 p2;
p.x = 3;
p.y = 2;
p2.x = 8;
p2.y = 45;
cout << p.x << " " << p.y << " " << p2.x << " " << p2.y << endl;
return 0;
}
Is there any benefit from any way? Thanks :D !
-
I believe that the difference is just that in C, you must use typedef, where as in C++, it is optional.
-
It's required?? I'm guessing that's changed in C99 - or am I wrong there, too?
-
I'm not sure about in C99 but it did not used to be required to use typedef. You would use the typedef version if you wanted to declare the struct like:
Point p;
If you did not use typedef you had to use:
struct Point p;
May have changed in C99, not sure.
edit: In case of any confusion I'm talking about C here not C++ obviously.
-
Right, that seems appropriate.