Next: , Previous: , Up: Overflow Check Handling in GNAT   [Contents][Index]


6.4.3 Specifying the Desired Mode

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

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:

1use base type for intermediate operations (STRICT)
2minimize intermediate overflows (MINIMIZED)
3eliminate 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).


Next: , Previous: , Up: Overflow Check Handling in GNAT   [Contents][Index]