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

It's not so much convenience... it's more the fact that the compiler can and will optimise out "if (MyValue>=ord(Low(TMyType))) and (MyValue<=Ord(High(TMyType))) then" because it has every reason to assume that MyValue cannot possibly take on a value that's less than Low(TMyType) or greater than High(TMyType), hence it gets shortcut and assumed to always be True.

No. MyValue is an integer. Hence the ord().

Obviously the check must be done before the typecast, not after...

Let me make that more explicit:

if MyIntValue is TMyEnum then
  MyValue:=TMyEnum(MyIntValue);
or
MyValye:=MyIntValue as TMyEnum;

That's why I said it it is not at odds with the fact that the compiler can
assume MyValue is always valid.

Michael.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to