You are not logged in.
Pages: 1
I have written linked lists many times, but I'm stumped by this error.
header
#include <stdio.h>
typedef struct
{
char *str;
struct strstack *next;
} strstack;
void connect(struct strstack *a, struct strstack *b);
source
#include <stdio.h>
#include "strstack.h"
void connect(struct strstack *a, struct strstack *b)
{
a->next = b;
}
errors
gcc -g -O2 --std=c99 -c strstack.c
strstack.c: In function 'connect':
strstack.c:7: error: dereferencing pointer to incomplete type
make: *** [strstack] Error 1
Does anybody have any idea what causes this?
Last edited by Lexion (2009-09-12 23:48:49)
urxvtc / wmii / zsh / configs / onebluecat.net
Arch will not hold your hand
Offline
Yes.
Your typedef is silly.
Replace with
typedef struct stack_s
{
char *str;
struct stack_s *next;
} stack_t;
or similar.
You have to name the struct, and use the struct name when declaring the next pointer. You can typedef it too, if you want to, but that name can't be used in the struct declaration.
Offline
To clarify: You don't declare "struct strstack" anywhere. You declare an unnamed struct, and typedef that struct as strstack.
Offline
There is an article on this at http://www.netalive.org/codersguild/posts/1753.shtml
Try:
struct strstack
{
char *str;
struct strstack *next;
} ;
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Thanks all, it works great!
urxvtc / wmii / zsh / configs / onebluecat.net
Arch will not hold your hand
Offline
Pages: 1