Jump to content
  • Advertisement
Sign in to follow this  
Sync Views

typedefs

This topic is 3711 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
Advertisement
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
Sign in to follow this  

  • 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!