[fpc-pascal] New Warnings with fpc >= 3.2.0 (fredvs)

Sven Barth pascaldragon at googlemail.com
Sat Mar 14 21:08:54 CET 2020

Am 14.03.2020 um 17:18 schrieb fredvs via fpc-pascal:
> Hi Sven, sorry to come back, (dont forget I am a enum-guru now).
> But to be totally logic, in the previous code:
>> if kind = tabulatorkindty(0) then
> Should it not be something illegal because of definition:
>> tabulatorkindty =
>> (tak_none := 1,tak_left,tak_right,tak_centered,tak_decimal);
> the values assigned are tak_none = 1, tak_left = 2, tak_right = 3,
> tak_centered = 4, tak_decimal = 5
> and 0 is never assigned.
> Then (re-imho) there is something strange with initialization with 0 because
> 0 should be out of range.
The thing about the default value is that it's some known value, not 
necessarily some legal value. Also what value should the compiler select 
otherwise? The first one? The last one? The one with the lowest value? 
(enum values can be negative by the way) The one with the highest? The 
same also applies to range types: MyRange = 3..6.
0 is simply a sane default. It's the task of the programmer to make sure 
that their code works correctly nevertheless. Not to mention that 0 
initialization is something that's very likely to be supported by the 
operating system: for global variables without explicit value set the 
BSS section is used which tells the OS to allocate a certain memory area 
with its content set to 0 (this area contains all unitialized global 
variables). Same is also true for class instances: it's easy to simply 
allocate the whole memory area to zero, however to initialize each and 
every field to a known default is much more costly (see the performance 
impact that management operators had for managed fields inside classes, 
before that was improved again).


More information about the fpc-pascal mailing list