<div dir="ltr">Try the following:<br><br>type list = ^node;<br>
node = record<br>
data : Variant;<br>
next : list;<br>
end;<br><br><br>Variant can store a lot pf data types, however please note that it's very slow type.<br>You also must remember that Pascal is Strong typed, unlike C or duck type languages.<br><br>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'.<br>
<br>Ido<br><br clear="all"><a href="http://ik.homelinux.org/">http://ik.homelinux.org/</a><br>
<br><br><div class="gmail_quote">2010/4/23 spir ☣ <span dir="ltr"><<a href="mailto:denis.spir@gmail.com">denis.spir@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello,<br>
<br>
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?<br>
<br>
type list = ^node;<br>
node = record<br>
data : ???;<br>
next : list;<br>
end;<br>
<br>
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)?<br>
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...<br>
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.<br>
p^ := <I'll tell you soon, just book the place><br>
(The compiler warns about not initialised pointers.)<br>
<br>
Pointers (sic!) to implementations of similar things (including trees) welcome...<br>
More generally, I cannot find in the library units for common data structures (sequence, associative table, set (the collection)...).<br>
<br>
Denis<br>
________________________________<br>
<br>
vit esse estrany ☣<br>
<font color="#888888"><br>
<a href="http://spir.wikidot.com" target="_blank">spir.wikidot.com</a><br>
_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br>
</font></blockquote></div><br></div>