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

Ondrej Pokorny lazarus at kluug.net
Tue Jul 3 20:46:47 CEST 2018


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.

Ondrej



More information about the fpc-devel mailing list