Solved

Struct containg the struct

Posted on 2004-10-20
3
369 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

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 recursion 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.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now