The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,261 other subscribers

Bogus W1036 ? 

Posted by jpluimers on 2020/07/30

Reminder to self for checking if this still fails:

[WayBack] Bogus W1036 ? Documentation: … “If you do not explicitly initialize a global variab… – Stefan Glienke – Google+

Documentation: http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Variables_(Delphi)

“If you do not explicitly initialize a global variable, the compiler initializes it to 0.”

{$APPTYPE CONSOLE}

var
  i: Integer;
begin
  Writeln(i);
end.

Error:

[DCC Warning] Project1.dpr(6): W1036 Variable 'i' might not have been initialized

–jeroen

2 Responses to “Bogus W1036 ? ”

  1. abouchez said

    Yes. All global variables are allocated at once when the exe is loaded, as a whole private in-memory section, and filled by the Operating System executable loader with zeros.

    This warning is indeed paranoid, and only affect the dpr (not the units).
    In fact, this is a compiler optimization. This variable i is not identified as a global variable, but a local variable – typically it could be used in a loop.
    Usually, I never put any loop and such in the main begin…end block of the dpr. I try to always use an explicit sub-function.

    So this is not a bug, this is a feature, from the compiler point of view.

    • Stefan Glienke said

      I cannot count how often I had weird issues with all kinds of things just because I thought that just quickly testing something in the dpr main was a good idea.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.