delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/12/15:15:50

From: Thomas Demmer <demmer AT LSTM DOT Ruhr-UNI-Bochum DOT De>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Definition of struct for dynamic linked list.
Date: Thu, 12 Mar 1998 21:11:52 +0100
Organization: Lehrstuhl fuer Stroemungsmechanik
Lines: 51
Message-ID: <35084188.C1C88B47@LSTM.Ruhr-UNI-Bochum.De>
References: <3507af4d DOT 5302402 AT news DOT manawatu DOT gen DOT nz>
NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de
Mime-Version: 1.0
Xcanpos: shelf.01/199803270101!0010482306
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019