Mail Archives: djgpp/1998/03/12/15:15:50
Michael Langton wrote:
>
> Hello,
> I'm getting practice with C (I've done all this before in pascal) and
> DJGPP by making some ADT units, and I've come across the following
> problem: In this code, (for linked lists, stacks, etc.)
>
> typedef int stype;
> struct nodeS {
> stype data;
> nodeS *next;
> }
>
> I'm getting "parse error before 'nodeS'", but not all the time. It
> sometimes works when I try it in a new program, and other
> circumstances which I'm not quite sure about.
>
> Can anybody point out why this might be occurring?
Because the definition of nodeS is not yet complete.
struct nodeS{
struct nodeS *next;
char *data;
};
is the solution. Notice I changed the order, so you routines
can act upon nodeS variables without knowing what the actual
data is. So you can have
struct nodeS root, foo;
double bar;
foo->data = malloc(sizeof(double));
memmove(foo->data, &bar, sizeof(bar));
insertTail(&root,&foo);
You might want to look at insqe() and remque() in libc, that help
implementing double linked lists.
--
Ciao
Tom
*************************************************************
* Thomas Demmer *
* Lehrstuhl fuer Stroemungsmechanik *
* Ruhr-Uni-Bochum *
* Universitaetsstr. 150 *
* D-44780 Bochum *
* Tel: +49 234 700 6434 *
* Fax: +49 234 709 4162 *
* http://www.lstm.ruhr-uni-bochum.de/~demmer *
*************************************************************
- Raw text -