[fpc-devel] Local boolean variables not always initalized with false by default?

Jonas Maebe jonas.maebe at elis.ugent.be
Wed Sep 16 12:01:32 CEST 2009


On 16 Sep 2009, at 10:49, theo wrote:

>> Uninitialised means exactly that: not initialised, neither with  
>> false,
>> nor with true
>
> OK, that's what I thought. So Delphi is "hiding" a coding bug here.

Well, it's not Delphi's fault either. It could just as well have been  
the other way round (with the value being non-0 in Delphi, and 0 in  
FPC).

> Hard to find such little things ;-)

You can fairly expose most such bugs in FPC by compiling with -gt, - 
gtt or -gttt. All of these will initialise all local variables (and  
out parameters) with specific (non-0) values when the function starts.  
-gtttt initialises everything with 0, but that is generally more  
likely to hide bugs than expose them. It doesn't hurt to try that one  
too though.

Note: I would strongly recommend against using -gtttt in shipping  
software to have automatic zero-initialisation of local variables,  
since the initialisation is performed in a very inefficient way.


Jonas

PS: your system clock seems to be off by an hour, could you correct  
it? (it messes up thread ordering of messages)



More information about the fpc-devel mailing list