[fpc-devel] Wrong docs: not initialized global variables

Florian Klämpfl florian at freepascal.org
Tue Jul 3 20:54:04 CEST 2018


Am 03.07.2018 um 20:46 schrieb Ondrej Pokorny:
> On 03.07.2018 19:53, Stefan Glienke wrote:
>> SetLength should not cause anything uninitialized.
>>
>> It enlarges or shrinks the data and keeps any prior data as it was, new allocated memory is zeroed (at least that is 
>> how it works in the Delphi RTL and I would be very surprised if FPC would do any different).
> 
> This is not relevant to what I wrote about.
> 
>> The core issue imo is temp var reuse the compiler does which causes hidden data reusage/copy which is only an issue 
>> with dynamic arrays because they don't have CoW semantic when writing to some index. So the temp variable still points 
>> to the first array which then gets passed to the next function as result. There a call to SetLength applies copy on 
>> write semantics carrying over any content from the previous array that is still in the temp variable to the newly 
>> allocated array.
>>
>> I think we discussed this on friday - maybe I did not make my point clear enough.
> 
> Again, implicit initialization / zeroing / whatever in the generated code is not relevant about what I wrote about.
> 
> My point is about the warning only.

The warning happens also for any other call which takes an uninitialized variable as var parameter (see e.g. fillchar). 
So the warning increases only orthogonality of the language. It was an oversight that it not was thrown before.




More information about the fpc-devel mailing list