[fpc-pascal] re-newing a pointer
spir ☣
denis.spir at gmail.com
Wed Apr 28 13:11:40 CEST 2010
Hello,
It seems that once a pointer has been assigned nil, it needs to be (re)allocated using new() before using it to (re)set its target:
...
p := nil; // pointer to Integer
...
new(p) ; p^ := 1;
Is this hypothesis correct?
Use case: Linked List
nil is used in the "toNext" field of a list's last node, as a kind of end mark. When a new node is appended, I need to "renew" the toNext pointer to let the now forelast node hold a reference to the new one:
// l is the list, n the new node
// currently, l.toLast^.toNext = nil
p := l.toLast;
new(p^.toNext) ; p^.toNext^ := n;
l.toLast^ := n;
Denis
________________________________
vit esse estrany ☣
spir.wikidot.com
More information about the fpc-pascal
mailing list