[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 416
  • Last Modified:

Struct containg the struct

I have a structure in a .h file that estentially is a node for a linked list, so it needs a pointer to the next node in the list of the same type of structure it is. Ex.

typedef struct{  // line 1
   struct Node *next; //line 2
   int x;
}Node;

I am getting a warning when ever the program calls Node.next saying assignment from imcompatible pointer type.  So far it appears to be no bugs involving these warning but, i bet there is somewhere i havent come across yet.  Do i need to fix this warning and how do i do so if so.  Also i tried to remove the struct in line 2 and that made my program have numerous erros when compiling.  Anyhelp would be appreciated

Thanks
0
whinson
Asked:
whinson
2 Solutions
 
avizitCommented:
You need to declare the struct  Node first as incomplete type

try this


struct Node;

typedef struct{
   struct Node *next;
   int x;
 } Node;

also read http://publications.gbdirect.co.uk/c_book/chapter6/structures.html
0
 
van_dyCommented:
typedef struct Node {
           struct Node *next;
           int x;
} Node;
0
 
dennis_georgeCommented:
Or

typedef struct _Node {
           struct _Node *next;
           int x;
} Node;
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now