Jump to content
  • Advertisement
Sign in to follow this  
Kazade

C, typedefs, and cyclic dependencies

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

Hi, I wrote a C-style math library a while ago in C++... so basically what I mean is the code won't compile in C, but the API is a similar style to OpenGL. Today I decided to clean it up and make it C99 compatible. I've never programmed in straight C before and I've come across a problem which probably has a simple solution I just can't find what it is... I have 2 header files, vec3.h and mat4.h, both need access to a structure in the other. In vec3.h I have this: typedef struct slVec3 { //Stuff } slVec3; in mat4.h (to avoid a cyclic dependency) I have a forward declaration (which may not be right!) typedef struct slVec3 slVec3; Now, if in a source file I include both files, e.g: #include "vec3.h" #include "mat4.h" I get the following errors: error: redefinition of typedef ‘slVec3’ previous declaration of ‘slVec3’ was here I'm obviously doing this wrong, any help would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
It's OK got it sorted. I had to forward declare like this:

struct slMath;

then when I used slMath I had to prefix it with 'struct' duh [smile]

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!