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

Sven Barth pascaldragon at googlemail.com
Sat Mar 24 23:00:38 CET 2018


Ondrej Pokorny <lazarus at kluug.net> schrieb am Sa., 24. März 2018, 20:49:

> This is not correct. Global simple variables are always initialized. At
> least in Delphi it is so:
> http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Variables_(Delphi) "If
> you do not explicitly initialize a global variable, the compiler
> initializes it to 0."
>

So, Delphi *does* document it. Okay, in that case the documentation needs
to be updated, cause up to now the assumption has been that this is an
implementation detail.

-----
>
> Another question about this sentence in FPC docs: "Managed types are
> always initialized: in general this means setting the reference count to
> zero, or setting the pointer value of the type to Nil."
>
> Does it mean I can assume a local string variable is always (=whenever
> the routine is called) initialized to ''? I.e. that TestB always returns
> 'a'?
>

For managed types this is indeed guaranteed. Otherwise there'd be
exceptions upon the first use of the variable as the RTL would assume that
the value is valid.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180324/a6bd8ebb/attachment.html>


More information about the fpc-devel mailing list