[fpc-devel] [Suggestion] Enumeration range-check intrinsic

Michael Van Canneyt michael at freepascal.org
Fri Jul 5 02:52:16 CEST 2019



On Fri, 5 Jul 2019, J. Gareth Moreton wrote:

> Ah, my apologies, Michael.
>
> I can see the issue of it being a convenience thing, but given that many 
> programmers have fallen foul of the lack of range checking in case 
> blocks, the typecasting necessary to avoid the problem is cumbersome, 
> adds a performance penalty and, ultimately, implies you should just not 
> use enumerations at all in that instance.

With this sentence you forbid storing or communicating enumerated values in any way: 
file, database, over network. It can be used only in a computer program and never
leave the context of the running program under any form. Because as soon as
it is somehow communicated, there is a chance it becomes invalid in return
communication.

Additionally you must then also abolish typecasting to an enumerated (or
pointers to enumerated values), since that also can be a source of invalid
values for an enumerated.

Or are you realy advocating we write code such as

Case MyInteger of
   0 : MyEnum:=ValueOrd0
   1 : MyEnum:=ValueOrd2;
else
   someError
end;
etc, whenever an integer must be changed to an enumerated ?

IMHO you would reduce the usabilty of enumerateds to almost zero by doing
so.

So you may want to reconsider, since in my experience most enumerateds at
one point do end up outside the program and typecasts are equally
widespread.

These patterns are so ubiquitous it is worthy of an intrinsic.

Michael.


More information about the fpc-devel mailing list