Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!postnews2.euro.net!news.wanadoo.nl!not-for-mail From: mhx@iae.nl (Marcel Hendrix) Subject: Re: Bug in beginner's linked-list code Newsgroups: comp.lang.forth Message-ID: <09561504028434@frunobulax.edu> Date: Thu, 31 Jan 2013 20:47:26 +0200 References: <961f6894-e6a6-4bed-88be-3c7531fe7c5e@googlegroups.com> X-Newsreader: iForth 2.0 console (October 21, 2006) Lines: 30 Organization: Wanadoo NNTP-Posting-Date: 31 Jan 2013 19:47:09 GMT NNTP-Posting-Host: s529d937f.adsl.online.nl X-Trace: 1359661629 dr5.euro.net 251 82.157.147.127:52842 X-Complaints-To: abuse@wanadoo.nl Xref: csiph.com comp.lang.forth:19327 laheadle@gmail.com writes Re: Bug in beginner's linked-list code > I am building a simple linked-list structure using FreeForth, > but my code has a bug. > When I create a node, then attempt to create another node and > insert the second node after the first node, I get a segmentation > fault. Can anyone help? > Here is the code that crashes: > 4 newNode 5 insertAfter ; You didn't type the ";" I hope? > ( start@ val -- ) > : insertAfter > newNode swap \ newNode@ start@ > dup nextNode \ -- newNode@ start@ cnext@ > 0- 0= IF \ last one > drop [..] > ; Try DUP instead of 0- . Several pieces seem to be missing from your algorithm. -marcel