Solved

Struct containg the struct

Posted on 2004-10-20
3
403 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

734 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