Node: Compatibility with Ada 83, Next: , Up: Compatibility Guide

Compatibility with Ada 83

Ada 95 is designed to be highly upwards compatible with Ada 83. In particular, the design intention is that the difficulties associated with moving from Ada 83 to Ada 95 should be no greater than those that occur when moving from one Ada 83 system to another.

However, there are a number of points at which there are minor incompatibilities. The Ada 95 Annotated Reference Manual contains full details of these issues, and should be consulted for a complete treatment. In practice the following are the most likely issues to be encountered.

Character range
The range of Standard.Character is now the full 256 characters of Latin-1, whereas in most Ada 83 implementations it was restricted to 128 characters. This may show up as compile time or runtime errors. The desirable fix is to adapt the program to accommodate the full character set, but in some cases it may be convenient to define a subtype or derived type of Character that covers only the restricted range.
New reserved words
The identifiers abstract, aliased, protected, requeue, tagged, and until are reserved in Ada 95. Existing Ada 83 code using any of these identifiers must be edited to use some alternative name.
Freezing rules
The rules in Ada 95 are slightly different with regard to the point at which entities are frozen, and representation pragmas and clauses are not permitted past the freeze point. This shows up most typically in the form of an error message complaining that a representation item appears too late, and the appropriate corrective action is to move the item nearer to the declaration of the entity to which it refers.

A particular case is that representation pragmas (including the extended DEC Ada 83 compatibility pragmas such as Export_Procedure), cannot be applied to a subprogram body. If necessary, a separate subprogram declaration must be introduced to which the pragma can be applied.

Optional bodies for library packages
In Ada 83, a package that did not require a package body was nevertheless allowed to have one. This lead to certain surprises in compiling large systems (situations in which the body could be unexpectedly ignored). In Ada 95, if a package does not require a body then it is not permitted to have a body. To fix this problem, simply remove a redundant body if it is empty, or, if it is non-empty, introduce a dummy declaration into the spec that makes the body required. One approach is to add a private part to the package declaration (if necessary), and define a parameterless procedure called Requires_Body, which must then be given a dummy procedure body in the package body, which then becomes required.
Numeric_Error is now the same as Constraint_Error
In Ada 95, the exception Numeric_Error is a renaming of Constraint_Error. This means that it is illegal to have separate exception handlers for the two exceptions. The fix is simply to remove the handler for the Numeric_Error case (since even in Ada 83, a compiler was free to raise Constraint_Error in place of Numeric_Error in all cases).
Indefinite subtypes in generics
In Ada 83, it was permissible to pass an indefinite type (e.g. String) as the actual for a generic formal private type, but then the instantiation would be illegal if there were any instances of declarations of variables of this type in the generic body. In Ada 95, to avoid this clear violation of the contract model, the generic declaration clearly indicates whether or not such instantiations are permitted. If a generic formal parameter has explicit unknown discriminants, indicated by using (<>) after the type name, then it can be instantiated with indefinite types, but no variables can be declared of this type. Any attempt to declare a variable will result in an illegality at the time the generic is declared. If the (<>) notation is not used, then it is illegal to instantiate the generic with an indefinite type. This will show up as a compile time error, and the fix is usually simply to add the (<>) to the generic declaration.

All implementations of GNAT provide a switch that causes GNAT to operate in Ada 83 mode. In this mode, some but not all compatibility problems of the type described above are handled automatically. For example, the new Ada 95 protected keywords are not recognized in this mode. However, in practice, it is usually advisable to make the necessary modifications to the program to remove the need for using this switch.