Your code is not safe because there is no evidence that valid memory is allocated at 'p'
.'dim as node ptr proot, ptail'
does not necessarily always produce 2 contiguous allocations in memory, and even if this were the case, the allocation order (between 'proot'
) may depend on the platform.
A solution (among the possible ones) to ensure 2 contiguous allocations in memory:
Code: Select all
as node ptr pnext
type nodeptrs '' to ensure that .proot and .ptail are contiguous in memory
as node ptr proot
as node ptr ptail
dim as nodeptrs pp
pp.proot = new node
pp.ptail = new node
pp.proot->pnext = pp.ptail
dim as node ptr ptr p = @pp.proot '' or p = @pp
?p & " " & p
?pp.proot & " " & pp.ptail