[fpc-pascal] Re: classes initialization

Jonas Maebe jonas.maebe at elis.ugent.be
Tue Mar 25 13:59:48 CET 2008


On 25 Mar 2008, at 14:40, L wrote:

> Not a fool proof test since random values have a chance of being  
> zero, but it basically shows:
> 1. global old heap object NOT zeroed
> 2. local old heap object NOT zeroed
> 3. local class zeroed
> 4. global class zeroed

The above terminology is wrong. Given your example

procedure show;
var rec: trec; c: tclass; o: tobj; po: pobj;  begin
...

What's on the stack is c (i.e., a pointer to a tclass instance) and po  
(a pointer to a tobj instance). Neither c nor po is automatically  
initialised with any value. Completely orthogonal to that is whether  
class instances or objects are initialised. As mentioned before, class  
instances are filled with zero. Object instances are just like any  
other data, so only fields of reference-counted types are initialised  
by the compiler.

The class and object constructors have no clue where the actual  
instance is located (stack, heap, shared memory, ...) nor where the  
pointer to the instance (if any) will be stored, so that does have any  
influence on their behaviour.


Jonas



More information about the fpc-pascal mailing list