Jump to content
  • Advertisement
Sign in to follow this  
afraidofdark

[C] structures which depend on each others

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

Hello, in the code belove, I create two structures List & Node. However, List needs Node* in its definition and Node needs to have a List* in it. Actually, The list code is from one of my old codes. But now I need to add a List* to Node definition however, compiler complains about Node* if I write List definition above, or if I write Node definition above than compiler complains about List*
what should I do ?


struct List;
struct Node;

typedef struct{
int length;
Node* pBegin;
Node* pEnd;
}List;

typedef struct{
// Heap
int priority;
List* subTrees;
// Queue
int arrivalTime;
int numberOfPage;
int jobNumber;
// next prev handle
struct Node* pNext;
struct Node* pPrev;
}Node;

Share this post


Link to post
Share on other sites
Advertisement

struct List;
struct Node;

struct List{
int length;
struct Node* pBegin;
struct Node* pEnd;
};
typedef struct List List;

struct Node
{
// Heap
int priority;
List* subTrees;
// Queue
int arrivalTime;
int numberOfPage;
int jobNumber;
// next prev handle
struct Node* pNext;
struct Node* pPrev;
};
typedef struct Node Node;



Share this post


Link to post
Share on other sites
My C is a bit rusty, but what if you do:

struct List;
struct Node;

typedef struct{
int length;
struct Node* pBegin;
struct Node* pEnd;
}List;

// etc...


I.e. prepend the struct keyword to the Node type?

EDIT: Ninja'd

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!