Next: Default Settings, Previous: Overflow Checking Modes in GNAT, Up: Overflow Check Handling in GNAT
The desired mode of for handling intermediate overflow can be specified 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 only the General
parameter is present, then the given MODE
applies
to expressions both within and outside assertions. If both arguments
are present, then General
applies to expressions outside assertions,
and Assertions
applies to expressions within assertions. For example:
pragma Overflow_Mode (General => Minimized, Assertions => Eliminated);
specifies that general 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 it can occur 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, a compiler switch -gnato? or -gnato??
can be used to control the checking mode default (which can be subsequently
overridden using 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 then it applies to all cases; if two digits are given, then the first applies outside assertions, and the second within assertions. Thus the equivalent of the example pragma above would be -gnato23.
If no digits follow the -gnato, then it is equivalent to
-gnato11,
causing all intermediate operations to be computed using the base
type (STRICT
mode).
In addition to setting the mode used for computation of intermediate
results, the -gnato
switch also enables overflow checking (which
is suppressed by default). It thus combines the effect of using
a pragma Overflow_Mode
and pragma Unsuppress
.