[fpc-devel] Are global variables guaranteed to be zero?

Hans-Peter Diettrich DrDiettrich1 at aol.com
Thu Nov 29 22:19:13 CET 2012


michael.vancanneyt at wisa.be schrieb:

>> Are there cases where locals are set to a sane initial state, e.g. for 
>> strings and dynamic arrays? What about (references to) objects?
> 
> Managed types are normally initialized. That means Ansistrings,
> UnicodeString, and COM interfaces and dynamic arrays (maybe I forget some)
> 
> Classes and objects are not. I am not sure about widestrings on Windows.
> 
> But again, not always:
> 
> For instance
> 
> Function a(B : Integer) : Ansistring;
> 
> begin
>   Result:=Result+' something';
> end;
> 
> You would think that Result is initialized because it is managed: it is 
> an ansistring. In fact, it is not initialized, leading sometimes to 
> surprises.

I'd expect that the Result is passed in as a reference, which is 
initialized before the call. Just like record results are handled.

DoDi




More information about the fpc-devel mailing list