View Issue Details

IDProjectCategoryView StatusLast Update
0033558FPCDocumentationpublic2018-04-14 12:01
ReporterOndrej PokornyAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Product VersionProduct Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0033558: Wrong docs: not initialized global variables
Descriptionhttps://www.freepascal.org/docs-html/ref/refse24.html

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.
TagsNo tags attached.
Fixed in Revision1479
FPCOldBugId
FPCTarget
Attached Files

Activities

Thaddy de Koning

2018-04-04 11:54

reporter   ~0107583

Last edited: 2018-04-04 12:01

View 4 revisions

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.

Ondrej Pokorny

2018-04-04 12:01

developer   ~0107584

Thaddy, this report is about GLOBAL variables. Why do you have the need to write your useless comments everywhere?

Thaddy de Koning

2018-04-04 12:02

reporter   ~0107585

And just by implementation..... Our posts crossed. Does that make it clear?

Ondrej Pokorny

2018-04-04 14:48

developer   ~0107596

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.

Thaddy de Koning

2018-04-04 17:13

reporter   ~0107603

Last edited: 2018-04-04 17:15

View 3 revisions

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.

Ondrej Pokorny

2018-04-04 20:06

developer   ~0107613

> 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.

Serge Anvarov

2018-04-05 05:41

reporter   ~0107621

See also https://forum.lazarus.freepascal.org/index.php/topic,39438.0.html

Michael Van Canneyt

2018-04-14 11:54

administrator   ~0107777

I documented it, and added a small example of the pitfalls of relying on this.

Ondrej Pokorny

2018-04-14 12:01

developer   ~0107779

Thank you!

Issue History

Date Modified Username Field Change
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