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

Thorsten Engler thorsten.engler at gmx.net
Sat Apr 14 10:39:44 CEST 2018


How about following the same schema as with classes?

If 1 is TMyEnum then
  //use hard cast here


> -----Original Message-----
> From: fpc-devel <fpc-devel-bounces at lists.freepascal.org> On Behalf
> Of Ondrej Pokorny
> Sent: Saturday, 14 April 2018 18:32
> To: fpc-devel at lists.freepascal.org
> Subject: Re: [fpc-devel] Dangerous optimization in CASE..OF
> 
> On 14.04.2018 10:24, Michael Van Canneyt wrote:
> > On Sat, 14 Apr 2018, Ondrej Pokorny wrote:
> >
> >> Effectively, you should be able to use:
> >> var
> >>   E: TMyEnum;
> >> begin
> >>   if TryIntToEnum(1, E) then
> >>
> >> instead of
> >>   if TryIntToEnum(TMyEnum, 1, E) then
> >
> > I am all for it, although I think the "as" syntax is more elegant,
> and
> > that has my preference.
> 
> I am for both variants. If you want the "hard check" with exception
> on error you use the "as" syntax, whereas if you want the "soft
> check" with boolean result, you use TryIntToEnum.
> 
> IntToEnum could be added as an alternative to the "as" syntax for
> the sake of consistency, if the demand is present.
> 
> But with my experience and knowledge of the compiler, the
> TryIntToEnum variant will be harder to implement for me. I am a
> little bit struggling with it.
> 
> Ondrej
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel




More information about the fpc-devel mailing list