[fpc-devel] [Suggestion] Enumeration range-check intrinsic
J. Gareth Moreton
gareth at moreton-family.com
Tue Jul 2 21:44:13 CEST 2019
I like the idea of using existing operators since that avoids extra
intrinsics and the risk of breaking code that uses a function with the
same proposed name.
The "as" operator is possible for assignment, although I'm not the
biggest fan of run-time errors (although they have their uses). The
"is" operator sounds like a good partner as well, like how as and is are
used to check if an object belongs to a particular class family.
e.g. "If (Value is TEnumType) then" returning False if it is outside of
the range.
Though I'm only a developer and not one of the moderators or
administrators, the patch in principle has my blessing. There might be
options for optimisation further down the line, but we'll get to that later!
Gareth aka. Kit
On 02/07/2019 20:15, Michael Van Canneyt wrote:
>
>
> Don't forget to check the post of Ondrej.
>
> Personally, I think using 'as' to convert an integer to an enum with
> range
> check is still the best approach. It does not require new intrinsics (far
> too many of those already) and does what it says. To simply check if an
> integer is a valid enum, I think 'is' would be equally suitable.
>
> Michael.
>
> On Tue, 2 Jul 2019, J. Gareth Moreton wrote:
>
>> Aah, thank you.
>>
>> On 02/07/2019 19:56, Michael Van Canneyt wrote:
>>>
>>>
>>> On Tue, 2 Jul 2019, J. Gareth Moreton wrote:
>>>
>>>> I don't recall a conversation where such an intrinsic is seen as
>>>> desirable, but if such a construct is desirable, then that's a good
>>>> thing since it will help patch up this problem.
>>>>
>>>> As for the Delphi problem, it's second-hand information I heard
>>>> from a friend who uses Delphi at work and something about not
>>>> handling out-of-range enumerations was a deal-breaker from not
>>>> using FPC. I may have some details wrong though. But all that
>>>> side, would development of an intrinsic be an acceptable solution,
>>>> and what name are we going for? (One has to be careful we don't
>>>> break existing code if possible)
>>>
>>>
>>> See this thread:
>>>
>>> https://www.mail-archive.com/fpc-devel@lists.freepascal.org/msg35100.html
>>>
>>>
>>> Michael.
>>>
>>> _______________________________________________
>>> fpc-devel maillist - fpc-devel at lists.freepascal.org
>>> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>>
>>
>> ---
>> This email has been checked for viruses by Avast antivirus software.
>> https://www.avast.com/antivirus
>>
>
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190702/15d7be3e/attachment.html>
More information about the fpc-devel
mailing list