Next: , Up: Compatibility with Ada 83


F.1.1 Legal Ada 83 programs that are illegal in Ada 95

Some legal Ada 83 programs are illegal (i.e., they will fail to compile) in Ada 95 and thus also in Ada 2005:

Character literals
Some uses of character literals are ambiguous. Since Ada 95 has introduced Wide_Character as a new predefined character type, some uses of character literals that were legal in Ada 83 are illegal in Ada 95. For example:
             for Char in 'A' .. 'Z' loop ... end loop;

The problem is that 'A' and 'Z' could be from either Character or Wide_Character. The simplest correction is to make the type explicit; e.g.:

             for Char in Character range 'A' .. 'Z' loop ... end loop;

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 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 by the binder). 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. Another approach (assuming that this does not introduce elaboration circularities) is to add an Elaborate_Body pragma to the package spec, since one effect of this pragma is to require the presence of a package body.
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 methodological principle known as the “contract model”, the generic declaration explicitly indicates whether or not such instantiations are permitted. If a generic formal parameter has explicit unknown discriminants, indicated by using (<>) after the subtype name, then it can be instantiated with indefinite types, but no stand-alone variables can be declared of this type. Any attempt to declare such 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 is the potential incompatibility issue when porting Ada 83 code to Ada 95. It will show up as a compile time error, and the fix is usually simply to add the (<>) to the generic declaration.