[fpc-pascal] Pointers in Pascal!!

Hans MÃ¥rtensson cirkulation at maartensson.net
Tue Apr 29 20:10:27 CEST 2008


Joao Morais wrote:

> Jonas Maebe wrote:
>
>>
>> On 29 Apr 2008, at 15:35, Zaka E-Lab wrote:
>>
>>> It's possible to give a default initialization value to a defined type?
>>
>>
>> No, that is not possible.
>
>
> Except if your pointer is declared as a member of a class (which is 
> always assigned to nil by default)



But that would not work after the pointer was used and then it's memory 
freed.
So a better way might be:

Always when declaring pointers do it this way:

var p:  ^sometype = nil;

Then in stead of using the freemem, define your own procedure:

procedure myfreemem(var p: pointer);
begin if p<>nil then begin freemem(p); p:=nil end end;

(I would regard this a Pascal-improvement?)

Hans MÃ¥rtensson




More information about the fpc-pascal mailing list