[fpc-pascal] can the compiler zero any out parameter of procedure/function automatically?

Dennis dec12 at avidsoft.com.hk
Mon Jul 11 17:40:44 CEST 2016

I just found the cause of a strange bug is because I forgot to zero the 
out parameter of a procedure like.

procedure FindEvent (out TheEvent : TNotifyEvent);
   TheEvent := nil;//I forgot to add this line before all the 
processing, which sometimes did not assign to TheEvent at all
    .... long code...

when later, I called.
   aEvent : TNotifyEvent;
   if assigned(aEvent) then
    aEvent(nil);  -> cause serious error that crash the program.

I know it is my responsibility to initialize out parameters, but I think 
the compiler could help us by initializing all out parameters.
Am I the only one with this view?


More information about the fpc-pascal mailing list