Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-09

Local boolean variables not always initalized with false by default?

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

theo

Hello,

I don't know if this is a bug.

If fixed an old bug in the janSQL port.
http://forum.lazarus.freepascal.org/index.php/topic,6694.msg35412/ The problem was, that there was an uninitialized local boolean in

TjanSQL.selectFromJoin
...
var bAggregate:boolean;

if you insert a
writeln(bAggregate); in Line 758 (start of procedure!) then you get a 'true'.

It's fixed now using bAggregate:=False; there.
See http://www.theo.ch/lazarus/janSQLLaz.zip

While uninitialized variables are certainly a bad thing, it's still a bit strange why it defaults to 'true' in this case. It was 'false' with Delphi.

Thanks.

Reply by email

theo
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. Hard to find such little things ;-)

Thank you Jonas

Reply by email

Jonas Maebe
to theo: I don't know if this is a bug. If fixed an old bug in the janSQL port.…
theo wrote
While uninitialized variables are certainly a bad thing, it's still a bit strange why it defaults to 'true' in this case. It was 'false' with Delphi.

Uninitialised means exactly that: not initialised, neither with false, nor with true (both in Delphi and FPC). What you get is whatever random value happens to be in stack memory at that location, based on what previously executed code stored there.

Jonas

Reply by email

Jonas Maebe
to theo: OK, that's what I thought. So Delphi is "hiding" a coding bug here. Hard to find such…
theo wrote 5 lines
> 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)

Reply by email

theo
You can fairly expose most such bugs in FPC by compiling with -gt,

OK, thanks. I was not aware of this "feature".

PS: your system clock seems to be off by an hour,

Sorry. Better now?

Reply by email