1.2.64 $Q or $OV or $OVERFLOWCHECKS: Overflow checking

The {$Q+} or {$OV+} (MACPAS mode only) or {$OVERFLOWCHECKS ON} directive turns on integer overflow checking. This means that the compiler inserts code to check for overflow when doing computations with integers. When an overflow occurs, the run-time library will generate a run-time error 215: It prints a message Overflow at xxx, and exits the program with exit code 215.

Remark:Overflow checking behaviour is not the same as in Turbo Pascal since all arithmetic operations are done via 32-bit or 64-bit values. Furthermore, the Inc() and Dec standard system procedures are checked for overflow in Free Pascal, while in Turbo Pascal they are not.

Using the {$Q-} switch (or the {$OV-} switch in MACPAS mode) switches off the overflow checking code generation.

The generation of overflow checking code can also be controlled using the -Co command line compiler option (see the User’s Guide).

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