$R or $RANGECHECKS : Range checking

[next] [prev] [prev-tail] [tail] [up]

#### 1.2.65 $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 behavior, but no run-time errors will be generated.

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

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

Remark See the note on expression evaluation on 64-bit systems and the consequences for range checking and overflow checking.

[next] [prev] [prev-tail] [front] [up]