Sign in to follow this  

typedefs

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

How come there oftern used in places like this? d3d9types.h, line 51
typedef struct _D3DVECTOR {
    float x;
    float y;
    float z;
} D3DVECTOR;

Rather than just having:
struct D3DVECTOR {
    float x;
    float y;
    float z;
};

I see it alot on enums as well...

Share this post


Link to post
Share on other sites
Because those headers need to remain C compatible; "typedef struct" is a C idiom in that context, it prevents you from having to write "struct" in the declaration of a variable of that type (in C).

Share this post


Link to post
Share on other sites
In C, you have to prepend structure names with the struct keyword. For example:

struct D3DVECTOR
{
float x;
float y;
float z;
};

sturct D3DVECTOR vec;


To avoid this, C programmers often create typedefs so the struct names can be used directly. Of course using C++, we don't have that problem, but many C++ libraries are written with C interoperability in mind.

Share this post


Link to post
Share on other sites

This topic is 3459 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this