Solved

Struct containg the struct

Posted on 2004-10-20
3
389 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 SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to connect an iphone application to mysql database 10 204
Convert image to byte array 8 201
Adjust Mfcapp 29 166
C hashtable library 3 91
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

778 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