1.1.63 $R or $RANGECHECKS : Range checking

By default, the compiler doesn’t generate code to check the ranges of array indices, enumeration types, subrange types, etc. Specifying the {$R+} switch tells the computer to generate code to check these indices. 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.

The {$RANGECHECKS OFF} switch tells the compiler not to generate range checking code. This may result in faulty program behaviour, but no run-time errors will be generated.

Remark:The standard functions val and Read will also check ranges when the call is compiled in {$R+} mode.

In Delphi, range checking is only switchable on a procedure level. In Free Pascal, the {$R } directive can be used on an expression-level.