[fpc-pascal] GetMem should use out parameter ?

Skybuck Flying skybuck2000 at hotmail.com
Wed Aug 22 12:02:00 CEST 2007


Hello,

Does GetMem care about the memory contents of the pointer variable ?

If not the parameter should be out instead of var to prevent the following 
hint message:

  GetMem( node, sizeof(Tnode) );

Y:\Free Pascal\Units\Technical\TnodeList\version 0.08 port to free 
pascal\unit_TnodeList_version_009.pas(1015,3) Hint: Variable "node" does not 
seem to be initialized

GetMem could fail if out of memory, Delphi raises an OutOfMemory Exception.

What does Free Pascal do ?

Also I know when an exception is raised from inside a function the return 
value is never assigned to the variable.

At least not the result variable/return value.

However I am not so sure what happens to var parameters and out parameters, 
those can probably be changed, and later after they already changed an 
exception could be raised.

So whatever bad happens GetMem could always make sure the parameter is 
initialized to nil ?!

What your thoughts on this ?

Bye,
  Skybuck.




More information about the fpc-pascal mailing list