[fpc-pascal] pointer to anything
idokan at gmail.com
Fri Apr 23 10:57:34 CEST 2010
Try the following:
type list = ^node;
node = record
data : Variant;
next : list;
Variant can store a lot pf data types, however please note that it's very
You also must remember that Pascal is Strong typed, unlike C or duck type
The Pointer type store only memory address and not the data itself, so it's
not recommended to use it unless you control the memory allocation itself
for each 'data'.
2010/4/23 spir ☣ <denis.spir at gmail.com>
> Say I want to implement a kind of linked list which node data may be
> anything. Thus I cannot store data on place (in nodes), indeed; so it should
> be referenced. But pointers themselves are supposed to be typed. So, how can
> I do that?
> type list = ^node;
> node = record
> data : ???;
> next : list;
> I tried to use Pointer, but then I get an error saying the compiler found
> <some type> while it expected "untyped". What is the use of Pointer (without
> type for pointed data)?
> I also had a look at Variant; this looks like an ugly hack ;-) And avyway
> is not really generic. I need data to ba able to be anything, including
> first a linked list itself...
> Finaly, when trying to write the the algo for a given type, I get an issue
> since the def above is recursive, recursively pointing in fact. So, I need
> to stop the run somewhere by allocating the memory for non-yet-existing data
> pointed by a pointer -- I guess.
> p^ := <I'll tell you soon, just book the place>
> (The compiler warns about not initialised pointers.)
> Pointers (sic!) to implementations of similar things (including trees)
> More generally, I cannot find in the library units for common data
> structures (sequence, associative table, set (the collection)...).
> vit esse estrany ☣
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal