Specifying the Desired Mode (GNAT User’s Guide for Native Platforms)

#### 6.4.3 Specifying the Desired Mode ¶

You can specify the desired mode of for handling intermediate overflow using either the `Overflow_Mode` pragma or an equivalent compiler switch. The pragma has the form:

>     pragma Overflow_Mode ([General =>] MODE [, [Assertions =>] MODE]);

where `MODE` is one of

- `STRICT`: intermediate overflows checked (using base type)
- `MINIMIZED`: minimize intermediate overflows
- `ELIMINATED`: eliminate intermediate overflows

The case is ignored, so `MINIMIZED`, `Minimized` and `minimized` all have the same effect.

If you only specify the `General` parameter, the given `MODE` applies to expressions both within and outside assertions. If you specify both arguments, the value of `General` applies to expressions outside assertions, and `Assertions` applies to expressions within assertions. For example:

>     pragma Overflow_Mode
>       (General => Minimized, Assertions => Eliminated);

specifies that expressions outside assertions be evaluated in ‘minimize intermediate overflows’ mode and expressions within assertions be evaluated in ‘eliminate intermediate overflows’ mode. This is often a reasonable choice, avoiding excessive overhead outside assertions, but assuring a high degree of portability when importing code from another compiler while incurring the extra overhead for assertion expressions to ensure that the behavior at run time matches the expected mathematical behavior.

The `Overflow_Mode` pragma has the same scoping and placement rules as pragma `Suppress`, so you can use it either as a configuration pragma, specifying a default for the whole program, or in a declarative scope, where it applies to the remaining declarations and statements in that scope.

Note that pragma `Overflow_Mode` does not affect whether overflow checks are enabled or suppressed. It only controls the method used to compute intermediate values. To control whether overflow checking is enabled or suppressed, use pragma `Suppress` or `Unsuppress` in the usual manner.

Additionally, you can use the compiler switch `-gnato?` or `-gnato??` to control the checking mode default (which you can subsequently override using the above pragmas).

Here `?` is one of the digits `1` through `3`:

> `1` | use base type for intermediate operations (`STRICT`)
> `2` | minimize intermediate overflows (`MINIMIZED`)
> `3` | eliminate intermediate overflows (`ELIMINATED`)

As with the pragma, if only one digit appears, it applies to all cases; if two digits are given, the first applies to expressions outside assertions and the second within assertions. Thus the equivalent of the example pragma above would be `-gnato23`.

If you don’t provide any digits following the `-gnato`, it’s equivalent to `-gnato11`, causing all intermediate operations to be computed using the base type (`STRICT` mode).