Jump to content
Eternal Lands Official Forums
Sign in to follow this  
Florian

n00bish c question ...

Recommended Posts

Hi,

 

I have a problem with c ...

 

I need actors.h in eye_candy_wrapper.h to have the actor struct available.

On the other hand, I want to use ec_reference from eye_candy_wrapper.h in this actor struct, which is defined in actors.h.

 

Including eye_candy_wrapper.h in actor.h does not work, of course.

 

How can I resolve this circular dependency?

 

Florian

Share this post


Link to post
Share on other sites

Move the ec_reference to another file and #include that in both files with an #ifndef?

 

That way whichever file gets included first defines it.

 

A bit kludgy but what can you do?

Share this post


Link to post
Share on other sites
Hi,

 

I have a problem with c ...

 

I need actors.h in eye_candy_wrapper.h to have the actor struct available.

On the other hand, I want to use ec_reference from eye_candy_wrapper.h in this actor struct, which is defined in actors.h.

 

Including eye_candy_wrapper.h in actor.h does not work, of course.

 

How can I resolve this circular dependency?

 

Florian

Why do you need the actor structure in that .h file? A pointer to that structure I could understand, but you don't want to be duplicating all the info there.

Share this post


Link to post
Share on other sites

You can use an implicit struct declaration if you only need the reference.

 

/* sample for eycandy_wrapper.h */
typedef struct {
  struct _actor * actor;
} abc;

/* sample for actors.h */
typedef struct _actor {
  ...
} actor;

Edited by ago

Share this post


Link to post
Share on other sites

Usually you do it this way:

 

struct s; // declare structure

struct s a; // declare variable of type struct s. Here you do not know what fields struct s has, and hence can't access them.

 

struct s // definition of structure

{

...

}

 

// Now you can access fields of struct s.

Share this post


Link to post
Share on other sites

\o/ I guessed right!

 

where's my prize? ;)

Share this post


Link to post
Share on other sites

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×