Forum Navigation
You need to log in to create posts and topics.

linked lists in FB

Posted by: behmc <behmc@...>

Ok, I've been playing around with the idea of linked lists in FB and have
run into a snag.

I don't want to use global variables for this because a linked list is
supposed to be expandable and global structures are less expandable and
present another host of problems. What I was trying to do is create a
global record that defined the list element structure.

DIM Head& 'points to first element

DIM RECORD ListElement
DIM dataH&
DIM nextE& 'points to the next element
DIM END RECORD .ListElement

Then I create a new handle with a list element's size

elementRef& = FN NEWHANDLE(8)

This is a handle to a chunk of memory 8 bytes long (enough to hold two 4
byte handles).

Then I create my first test record which is a ListElement record

DIM Test1.ListElement

This creates an 8 byte record. Then I move the stuff from elementRef& into
the record (or at least i think i do)

Test1;8 = [elementRef&]

After that I assign Head&

Head& = @Test1

Head& does successfully point to the first element. The problem seems to
come later. I have Test2 and Test3 that follow the same basic outline of
how they are created. Then I assign them the nextE& value

Test1.nextE& = @Test2
Test2.nextE& = @Test3
Test3.nextE& = 0

Even if there is nothing in Test2 shouldn't Test1.nextE& have a value?
When I break into Macsbug using Debug II with Hex Data@Variable (correct
right?) I get 8 bytes of zero.

Sorry for the long post but I hope I made everything clear as to what I'm
doing. If anyone wants the unbroken code to see exactly what I'm doing let
me know.

TIA,
*Chris