[fpc-devel] [Suggestion] Enumeration range-check intrinsic
Jonas Maebe
jonas at freepascal.org
Sat Jul 13 14:02:28 CEST 2019
On 13/07/2019 13:52, Michael Van Canneyt wrote:
>
>
> On Sat, 13 Jul 2019, Jonas Maebe wrote:
>
>> On 13/07/2019 13:28, J. Gareth Moreton wrote:
>>> Okay, okay. So what do we do to stop all these bug reports and help
>>> programmers who get caught out by case blocks raising access
>>> violations? Are you effectively saying "don't ever use enumerations for
>>> external files and network signals" etc?
>>
>> Declare your enumation types so that the lowest and highest valid value
>> comprise the lowest and highest value representable by its storage:
>>
>> {$mode delphi}
>> {$z1}
>> type
>> tmyenum = (ea, eb, ec, emax = 255);
>>
>> That behaves the same both in FPC and in Delphi.
>
> This is a completely pointless definition, since for effective use you
> still need to add code to check that the value is a named one.
That is exactly what this thread is about: the ability to manually check
whether an enumeration value is one of the valid (named) values.
Jonas
More information about the fpc-devel
mailing list