[fpc-pascal] pointer magic
denis.spir at gmail.com
Tue Apr 27 10:16:37 CEST 2010
Two basic questions about pointer targets (I call target what is pointed to).
-1- untyped pointer allocation
In case of an untyped pointer, I read the compiler considers the target'size is 1 byte. There certainly is an operation to allocate memory for the target according to an existing piece of data. Something like
data := something
// Either p points to data where it was
// or a new memory area is silently reserved,
// data copied there, and p holds its address.
-2- reflexive pointing
The following works, but I do not understand how.
======= code =======
Classes, SysUtils; //, Variants;
// typed list version
List = ^Node;
Node = record
next : List;
data : ^Integer;
endNode : List;
with endNode^ do begin
data^ := 0;
next := endNode;
// end node flag
======= /code ======
The issue is: ^endNode holding a pointer to endNode, how is this kind of infinite self-referencing loop resolved by the compiler, at definition time?
PS: How else terminate a linked list in Pascal? (I must put something in the .next field of the last actual node, and this thing must be a List, ie a node pointer.)
vit esse estrany ☣
More information about the fpc-pascal