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

Michael Van Canneyt michael at freepascal.org
Thu Apr 5 00:34:39 CEST 2018



On Thu, 5 Apr 2018, Ondrej Pokorny wrote:

> On 04.04.2018 21:51, Jonas Maebe wrote:
>> On 04/04/18 20:26, Ondrej Pokorny wrote:
>>> The compiler initializes the variable implicitely for myself - this 
>>> is documented and I know it. There cannot be "wrong code behaviour" 
>>> (as you stated) and thus I cannot have an error. This is simple logic.
>>
>> "Wrong behaviour" is not the same as "undefined behaviour" or "crash". 
>> It merely means "something different than the programmer intended". It 
>> is of course possible that you wanted the behaviour that you get when 
>> the variable contains the empty string, nil or 0, but because this 
>> initialisation is implicit rather than explicit, the compiler does not 
>> rely on this. After all, it is equally possible that you forgot to 
>> assign the correct (non-nil/0/empty string) value to the variable 
>> before using it the first time (in which case it would be an error in 
>> the program).
>
> How can I forget to assign the correct (non-nil/0/empty string) value to 
> a variable? Oh god, this is such a crazy argument - completely out of 
> the reality. At latest the first execution of the program tells me about 
> this error. Warnings should warn me about possible errors that I cannot 
> easily find and that are potentially dangerous.
>
> No, this discussion is useless.

What, because you do not agree ?

Pascal states that variables should be considered uninitialized.

So, the compiler tells you that you didn't initialize a variable before using
it.

Whether this variable is managed or not is irrelevant to the discussion.

Now, that the compiler initializes a managed type with a well-known value is
only relevant for its internal bookkeeping, but this says nothing about the
awareness of the programmer of this fact.

So it warns.

Now, it is also correct that the compiler developers are aware that many 
people rely on this implementation detail.

So, to make it possible for you to distinguish between managed and unmanaged 
types, there are 2 separate warnings.

But indeed, you must still actually indicate to the compiler that you rely on
these well-known values being used, and you do this by actively telling it 
that this particular warning is unnecessary.

So the Lazarus team would be better off giving a list of warnings that are permitted to
be switched off and then your whole problem is solved.

Michael.



More information about the fpc-devel mailing list