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

Bart bartjunk64 at gmail.com
Thu Apr 5 19:34:41 CEST 2018


On Thu, Apr 5, 2018 at 4:22 PM, Karoly Balogh (Charlie/SGR)
<charlie at scenergy.dfmk.hu> wrote:


> But again, it's zeroed out, not really "initialized". So for example if
> you have a type with say, 5..7 value range, it will still contain zero
> after start. Hence, uninitialized, therefore the warning is correct. (See
> below for examples.)

Never realized this...


> type
>   qq = (foo, bar, klepp, mopp, fubb);
>   q = klepp..fubb;
>
> var
>   c: q;
>
> begin
>   writeln(ord(c)); // will write 0;
>   writeln(c); // will fail with runtime error (out of range)
> end.
>
>
> And:
>
> {$MODE OBJFPC}
>
> type
>   qq = (foo, bar, klepp, mopp, fubb);
>   q = klepp..fubb;
>
> type
>   clfoo = class
>     c: q;
>   end;
>
> var
>   x: clfoo;
>
> begin
>   x:=clfoo.create;
>   writeln(ord(x.c)); // write 0;
>   writeln(x.c); // runtime error (out of range)
> end.
>
> Tested with FPC 3.0.4 32bit on macOS.
>
> I'd be interesting to know if Delphi behaved otherwise.

D7 behaves the same, except that in the 2nd example the line
writeln(x.c) cannot be compiled, so I could not test that, but the
line above prints 0.

Bart



More information about the fpc-devel mailing list