Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-10-2003, 06:59 AM   #1
Registered: Sep 2003
Location: Newcastle upon Tyne
Distribution: Red Hat 9
Posts: 42

Rep: Reputation: 15
Yet another pointers problem in C

I got my double linked list to work (albeit with some warning messages that I don't understand yet. I have now moved on to produce a program that produces a tree structure. This time I am getting the error "dereferencing pointer to incomplete type" on lines 22,23 and 24 and I don't understand why. I am also getting "passing arg 1 of `initialise_node' from incompatible pointer type" on line 31, which I also don't understand. Any help would be gratefully received. I will post my full set of C examples on the web when I have got them working. (I am using gcc 3.2.1 on RedHat 9).

/* Example to use pointers to construct a 4 level tree with a 4 digit
code to locate nodes within the tree*/

my program pointertree.c:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct
int h_code[4];
char nodename[30];
struct node *parent, *child[10];
} node;

int main (void)

void initialise_node(struct node *n)
/* a procedure for intialising nodes */
int j; /* local variable */
for (j=0; j<3; ++j) n->h_code[j] = 0; /*line 22 with error */
for (j=0; j<3; ++j) printf("node->h_code[%i] = %i\n",n->h_code[j]);
for (j=0; j<10; ++j) n->child[j] = 0; /* point children to null */

printf("Starting program\n");
node *rootnode, *newnode;
rootnode = (node *) malloc (sizeof (node));
printf("calling initialise node\n");
initialise_node(rootnode); /* line 31 with error */

Compiler errors:
[nmansys@mmme1 c_examples]$ gcc pointertree.c
pointertree.c: In function `initialise_node':
pointertree.c:22: dereferencing pointer to incomplete type
pointertree.c:23: dereferencing pointer to incomplete type
pointertree.c:24: dereferencing pointer to incomplete type
pointertree.c: In function `main':
pointertree.c:31: warning: passing arg 1 of `initialise_node' from incompatible pointer type
Old 11-10-2003, 07:49 AM   #2
LQ Guru
Registered: Nov 2002
Location: Durham, England
Distribution: Fedora Core 4
Posts: 1,565

Rep: Reputation: 47
I think you're using typedefs incorrectly again. You have typedefed it, so change the function prototype of initialise_node to just "node* n"
Old 11-10-2003, 07:50 AM   #3
Registered: Nov 2003
Location: Ronneby, Sweden
Posts: 555

Rep: Reputation: 30
Drop keyword struct in this line:

void initialise_node(struct node *n)

Old 11-10-2003, 08:35 AM   #4
Registered: Sep 2003
Location: Newcastle upon Tyne
Distribution: Red Hat 9
Posts: 42

Original Poster
Rep: Reputation: 15
Thanks Martin. Its compiling fine now.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers in c++ marios_auth Programming 1 06-16-2004 08:20 AM
Newbie problem with pointers in C. chris.hicks Programming 2 11-08-2003 02:00 PM
pointers in C again h/w Programming 9 10-29-2003 11:46 PM
simple problem with pointers Jo_Nak Programming 2 06-17-2003 04:46 PM
Need some pointers in this problem (inside...) Vlad_M Linux - General 8 09-04-2002 03:45 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:05 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration