[fpc-devel] Managed Types, Undefined Bhaviour

Michael Van Canneyt michael at freepascal.org
Sat Jun 30 10:54:17 CEST 2018



On Sat, 30 Jun 2018, Florian Klämpfl wrote:

> Am 30.06.2018 um 08:47 schrieb Sven Barth via fpc-devel:
>> Willibald Krenn <Willibald.Krenn at gmx.at <mailto:Willibald.Krenn at gmx.at>> 
> schrieb am Sa., 30. Juni 2018, 08:01:
>>
>>       TBH, I didn't know this issue existed in Delphi and I've done my 
> share of Delphi over time. I still maintain that
>>     for managed types the compiler is responsible for some 
> minimal initialization (like it's done for records etc, no?). 
>> 
>> 
>> The variables we're talking about here *are* initialized.
>
> Maybe the term initialized is wrong and confusing. They are not initialized 
> in the sense of having defined values as 
> global variables have. Non-global managed types should not be considered as 
> being initialized (never!, like any other 
> type), this is also why the compiler warns (!) about this. They can be 
> considered as being "setup" by the compiler.
>
>> They contain valid values and none of the internal RTL 
>> routines will crash when used with them. Everyone however expects result 
> variables of those to be initialized to Nil and 
>> that is simply *not* a guaranteed given.
>> Also records only initialize their managed fields. All others are left as 
> garbage.
>> 
>
> Managed fields of records are "setup" ;)

I will add a section about this in the documentation, seeing that people
often confuse the 2 concepts.

Michael.


More information about the fpc-devel mailing list