weird linked list behaviour..
Posted: Thu Dec 23, 2004 10:23 pm
Hello everyone!
Although I purchased PB quite some time ago, I never really looked into it much, which is why I've placed this query in the beginner's forum
Anyhow I've been playing around with structures, pointers, and linked lists, to try to get a feel for these methods of memory management. I've run into a bit of a hitch however which can be demonstrated with the following code (non relevant structure test stuff removed for brevity):
Ok. If I run the code as-is.. it runs fine. If I uncomment those extra Debug Lines, the first one goes through ok, but the second one crashes the program..! I know that using PeekS and PeekL on the pointer is the 'hard way' of doing this, but once again this was just an exercise to make sure that what made sense in my head would work out in the real-world.
What really confuses me is if I replace NextElement (mylist()) with LastElement (mylist)), the code runs flawlessly! (Even with the weird pointer stuff!) I've asked about this on IRC, and for one person they had said that the code worked either way..? Making me wonder if maybe I'm just on crack :roll:
Anyways.. I've been sure to update to 3.92 using the SmartUpdate program, but perhaps if I see more people claiming this works for them, I will just re-install from scratch!
Any help will be appreciated!
Although I purchased PB quite some time ago, I never really looked into it much, which is why I've placed this query in the beginner's forum

Code: Select all
;Linked list/pointer exercise
NewList mylist.s()
AddElement (mylist())
mylist () = "element 1"
AddElement (mylist())
mylist () = "element 2"
*ptr = FirstElement (mylist())
Debug mylist()
;Debug PeekS(PeekL(*ptr + 8))
*ptr = NextElement (mylist())
Debug mylist()
;Debug PeekS(PeekL(*ptr + 8))
What really confuses me is if I replace NextElement (mylist()) with LastElement (mylist)), the code runs flawlessly! (Even with the weird pointer stuff!) I've asked about this on IRC, and for one person they had said that the code worked either way..? Making me wonder if maybe I'm just on crack :roll:
Anyways.. I've been sure to update to 3.92 using the SmartUpdate program, but perhaps if I see more people claiming this works for them, I will just re-install from scratch!
Any help will be appreciated!
