[fpc-devel] [Suggestion] Enumeration range-check intrinsic

Ondrej Pokorny lazarus at kluug.net
Wed Jul 3 09:11:16 CEST 2019


On 03.07.2019 08:58, Ondrej Pokorny wrote:
>
> BTW I was always convinced that an explicit typecast switches off 
> range checking. And now I open the documentation 
> https://www.freepascal.org/docs-html/prog/progsu65.html and I read 
> this: (citation)
> /If, at run-time, an index or enumeration type is specified that is 
> out of the declared range of the compiler, then a run-time error is 
> generated, and the program exits with exit code 201. This can happen 
> when doing a typecast (implicit or explicit) on an enumeration type or 
> subrange type./
>
More fun:

program Project1;
{$R+}
type
   TSubRange = 1..2;
var
   S: TSubRange;
begin
   S := Default(TSubRange);
   Writeln(S);
end.

compiles and runs just fine. Why?

This does not compile:

program Project1;
{$R+}
type
   TSubRange = 1..2;
var
   S: TSubRange;
begin
   S := 0;
   Writeln(S);
end.

Ondrej

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190703/2650d6a0/attachment.html>


More information about the fpc-devel mailing list