0

I have a software where I have many errors like

Variable 'xxx' might not have been initialized

the question is when a variable is uninitialized, does its will have a default value (exemple false for boolean) or it's get a completely random number ? ex :

function test: boolean;
begin
end;

what will be the result of test ? false? or a total random value ? Other example:

function test: boolean;
var a: boolean;
begin
  if a then result := true
  else result := false;
end;

Same here, what will be the value of a? false? or a total random value ?

zeus
  • 12,173
  • 9
  • 63
  • 184
  • If it doesn't compile, how can it have a "value"? – user202729 Jan 31 '19 at 08:05
  • 2
    1) Random. 2) Random. See also [Is function's result always initialized?](https://stackoverflow.com/a/5429480/576719) and [local variable initialized in delphi?](https://stackoverflow.com/a/27189030/576719) – LU RD Jan 31 '19 at 08:11
  • 1
    Actually it is not necessarily random. It's whatever happens to be on the stack. Which could be repeatable. It's better to say that the value is undefined. – David Heffernan Jan 31 '19 at 08:24
  • Note that the result of the first (empty) function "returning" a boolean could even be a boolean containing, say, 57 or 93 (or any other undefined byte value), instead of true or false. – Rudy Velthuis Jan 31 '19 at 10:47
  • Note also that `Boolean(57)` evaluates to true, while `Boolean(57) = TRUE` evaluates to false. – LU RD Jan 31 '19 at 12:51

0 Answers0