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.

RemarkOverflow checking behavior 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 at the procedure level. In Free Pascal, the {$Q } directive can be used at the expression level.