[fpc-devel] Dangerous optimization in CASE..OF

Ondrej Pokorny lazarus at kluug.net
Sat Apr 14 00:50:04 CEST 2018


On 13.04.2018 23:16, Sven Barth via fpc-devel wrote:
> I wasn't talking about the boundaries. I meant undefined values inside 
> the enum. If we want such a cast operator to work with such enums as 
> well it should check for invalid values inside the enum, too. 
> Otherwise the operator isn't worth it and should be forbidden for such 
> enums.

How can I know what you mean with /"//What about enums with holes?//"/ ? :)

Nevertheless, as I already said in the reply to Martok, there are no 
undefined values inside an enum with assigned values. The values only 
don't have an alias. See the Delphi docs:

http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Simple_Types_(Delphi)#Enumerated_Types_with_Explicitly_Assigned_Ordinality

/type Size = (Small = 5, Medium = 10, Large = Small + Medium);/

/An enumerated type is, in effect, a subrange whose lowest and highest 
values correspond to the lowest and highest ordinalities of the 
constants in the declaration. In the previous example, the Size type has 
11 possible values whose ordinalities range from 5 to 15. (Hence the 
type array[Size] of Char represents an array of 11 characters.) Only 
three of these values have names, but the others are accessible through 
typecasts and through routines such as Pred, Succ, Inc, and Dec.

/IMO the docs are very clear about it. BTW. the Delphi 7 docs have the 
same information: 
http://docs.embarcadero.com/products/rad_studio/cbuilder6/EN/CB6_ObjPascalLangGuide_EN.pdf 
see page 5-7 and 5-8

Ondrej
////
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180414/861797c9/attachment.html>


More information about the fpc-devel mailing list