Solved

Struct containg the struct

Posted on 2004-10-20
3
394 Views
Last Modified: 2010-04-15
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
Comment
Question by:whinson
3 Comments
 
LVL 11

Accepted Solution

by:
avizit earned 125 total points
ID: 12367144
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
 
LVL 5

Assisted Solution

by:van_dy
van_dy earned 125 total points
ID: 12367151
typedef struct Node {
           struct Node *next;
           int x;
} Node;
0
 
LVL 5

Expert Comment

by:dennis_george
ID: 12367190
Or

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

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question