View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0033558||FPC||Documentation||public||2018-04-04 11:06||2018-04-14 12:01|
|Reporter||Ondrej Pokorny||Assigned To||Michael Van Canneyt|
|Product Version||Product Build|
|Target Version||3.2.0||Fixed in Version||3.1.1|
|Summary||0033558: Wrong docs: not initialized global variables|
There it says:
By default, simple variables in Pascal are not initialized after their declaration. Any assumption that they contain 0 or any other default value is erroneous: They can contain rubbish.
This is not correct. All global (including simple) variables are always initialized: http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Variables_(Delphi) "If you do not explicitly initialize a global variable, the compiler initializes it to 0."
Probably you forgot to add a note about global variables.
Note: I don't know and didn't test if the compiler really initializes global variables.
|Tags||No tags attached.|
|Fixed in Revision||1479|
This is ONLY the case for globals - and just by implementation!! -. Any other assumptions are that they are NOT initialized. (heap is, stack is not!) And even heap memory depends on the memory manager being used. Better to document as NEVER assume initialized memory. We have a Default() intrinsic.
||Thaddy, this report is about GLOBAL variables. Why do you have the need to write your useless comments everywhere?|
||And just by implementation..... Our posts crossed. Does that make it clear?|
No, it is not clear. What do you mean with "just by implementation"? That it is an implementation detail?
No, it is not an implementation detail. It's been well documented at least since the Delphi 7 days: http://docs.embarcadero.com/products/rad_studio/cbuilder6/EN/CB6_ObjPascalLangGuide_EN.pdf page 5-38.
It means the memory manager implementation is responsible for initializing heap memory. That can not be guaranteed by a compiler alone.
And stack memory is documented as always dirty.
Both arguments are also true for D7, btw.
> It means the memory manager implementation is responsible for initializing heap memory. That can not be guaranteed by a compiler alone.
> And stack memory is documented as always dirty.
Again: this report is about GLOBAL variables and not about heap/stack, please keep in topic.
||See also https://forum.lazarus.freepascal.org/index.php/topic,39438.0.html|
||I documented it, and added a small example of the pitfalls of relying on this.|
|2018-04-04 11:06||Ondrej Pokorny||New Issue|
|2018-04-04 11:06||Ondrej Pokorny||Status||new => assigned|
|2018-04-04 11:06||Ondrej Pokorny||Assigned To||=> Michael Van Canneyt|
|2018-04-04 11:54||Thaddy de Koning||Note Added: 0107583|
|2018-04-04 11:56||Thaddy de Koning||Note Edited: 0107583||View Revisions|
|2018-04-04 11:57||Thaddy de Koning||Note Edited: 0107583||View Revisions|
|2018-04-04 12:01||Ondrej Pokorny||Note Added: 0107584|
|2018-04-04 12:01||Thaddy de Koning||Note Edited: 0107583||View Revisions|
|2018-04-04 12:02||Thaddy de Koning||Note Added: 0107585|
|2018-04-04 14:48||Ondrej Pokorny||Note Added: 0107596|
|2018-04-04 17:13||Thaddy de Koning||Note Added: 0107603|
|2018-04-04 17:14||Thaddy de Koning||Note Edited: 0107603||View Revisions|
|2018-04-04 17:15||Thaddy de Koning||Note Edited: 0107603||View Revisions|
|2018-04-04 20:06||Ondrej Pokorny||Note Added: 0107613|
|2018-04-05 05:41||Serge Anvarov||Note Added: 0107621|
|2018-04-14 11:54||Michael Van Canneyt||Fixed in Revision||=> 1479|
|2018-04-14 11:54||Michael Van Canneyt||Note Added: 0107777|
|2018-04-14 11:54||Michael Van Canneyt||Status||assigned => resolved|
|2018-04-14 11:54||Michael Van Canneyt||Fixed in Version||=> 3.1.1|
|2018-04-14 11:54||Michael Van Canneyt||Resolution||open => fixed|
|2018-04-14 11:54||Michael Van Canneyt||Target Version||=> 3.2.0|
|2018-04-14 12:01||Ondrej Pokorny||Note Added: 0107779|
|2018-04-14 12:01||Ondrej Pokorny||Status||resolved => closed|