> What a glaring omission, no? 

Yes.

Also I am not totally convinced by the arguments to defend the choice of 0
as initialization of a enum var.
Imho, it would be much more logic to initialize with the first item and I do
not see what could be the problems.

Here the answer in fpc mailing-list

> 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).

Regards,
Sven  



--
Sent from: http://mseide-msegui-talk.13964.n8.nabble.com/


_______________________________________________
mseide-msegui-talk mailing list
mseide-msegui-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk

Reply via email to