[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This chapter describes the compatibility issues that may arise between GNAT and other Ada 83 and Ada 95 compilation systems, and shows how GNAT can expedite porting applications developed in other Ada environments.
E.1 Compatibility with Ada 83 E.2 Implementation-dependent characteristics E.3 Compatibility with Other Ada 95 Systems E.4 Representation Clauses E.5 Compatibility with DEC Ada 83
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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 subsections treat the most likely issues to be encountered.
E.1.1 Legal Ada 83 programs that are illegal in Ada 95 E.1.2 More deterministic semantics E.1.3 Changed semantics E.1.4 Other language compatibility issues
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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; |
'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; |
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.
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.
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
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).
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
type 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.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The worst kind of incompatibility is one where a program that is legal in
Ada 83 is also legal in Ada 95 but can have an effect in Ada 95 that was not
possible in Ada 83. Fortunately this is extremely rare, but the one
situation that you should be alert to is the change in the predefined type
Character
from 7-bit ASCII to 8-bit Latin-1.
Character
Standard.Character
is now the full 256 characters
of Latin-1, whereas in most Ada 83 implementations it was restricted
to 128 characters. Although some of the effects of
this change will be manifest in compile-time rejection of legal
Ada 83 programs it is possible for a working Ada 83 program to have
a different effect in Ada 95, one that was not permitted in Ada 83.
As an example, the expression
Character'Pos(Character'Last)
returned 127
in Ada 83 and now
delivers 255
as its value.
In general, you should look at the logic of any
character-processing Ada 83 program and see whether it needs to be adapted
to work correctly with Latin-1. Note that the predefined Ada 95 API has a
character handling package that may be relevant if code needs to be adapted
to account for the additional Latin-1 elements.
The desirable fix is to
modify 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.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
pragma Interface
and the floating point type attributes
(Emax
, Mantissa
, etc.), among other items.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
E.2.1 Implementation-defined pragmas E.2.2 Implementation-defined attributes E.2.3 Libraries E.2.4 Elaboration order E.2.5 Target-specific aspects
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Ada compilers are allowed to supplement the language-defined pragmas, and
these are a potential source of non-portability. All GNAT-defined pragmas
are described in the GNAT Reference Manual, and these include several that
are specifically intended to correspond to other vendors' Ada 83 pragmas.
For migrating from VADS, the pragma Use_VADS_Size
may be useful.
For
compatibility with DEC Ada 83, GNAT supplies the pragmas
Extend_System
, Ident
, Inline_Generic
,
Interface_Name
, Passive
, Suppress_All
,
and Volatile
.
Other relevant pragmas include External
and Link_With
.
Some vendor-specific
Ada 83 pragmas (Share_Generic
, Subtitle
, and Title
) are
recognized, thus
avoiding compiler rejection of units that contain such pragmas; they are not
relevant in a GNAT context and hence are not otherwise implemented.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Analogous to pragmas, the set of attributes may be extended by an
implementation. All GNAT-defined attributes are described in the
GNAT Reference Manual, and these include several that are specifically
intended
to correspond to other vendors' Ada 83 attributes. For migrating from VADS,
the attribute VADS_Size
may be useful. For compatibility with DEC
Ada 83, GNAT supplies the attributes Bit
, Machine_Size
and
Type_Class
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Elaborate_Body
or
Elaborate
pragmas, and then inhibit the generation of implicit
Elaborate_All
pragmas either globally (as an effect of the `-gnatE' switch) or locally
(by selectively suppressing elaboration checks via pragma
Suppress(Elaboration_Check)
when it is safe to do so).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Providing that programs avoid the use of implementation dependent and implementation defined features of Ada 95, as documented in the Ada 95 reference manual, there should be a high degree of portability between GNAT and other Ada 95 systems. The following are specific items which have proved troublesome in moving GNAT programs to other Ada 95 compilers, but do not affect porting code to GNAT.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The Ada 83 reference manual was quite vague in describing both the minimal required implementation of representation clauses, and also their precise effects. The Ada 95 reference manual is much more explicit, but the minimal set of capabilities required in Ada 95 is quite limited.
GNAT implements the full required set of capabilities described in the Ada 95 reference manual, but also goes much beyond this, and in particular an effort has been made to be compatible with existing Ada 83 usage to the greatest extent possible.
A few cases exist in which Ada 83 compiler behavior is incompatible with requirements in the Ada 95 reference manual. These are instances of intentional or accidental dependence on specific implementation dependent characteristics of these Ada 83 compilers. The following is a list of the cases most likely to arise in existing legacy Ada 83 code.
Pack
, or for more fine tuned control, provide
a Component_Size clause.
To get around this problem, GNAT also permits the use of "thin pointers" for access types in this case (where the designated type is an unconstrained array type). These thin pointers are indeed the same size as a System.Address value. To specify a thin pointer, use a size clause for the type, for example:
type X is access all String; for X'Size use Standard'Address_Size; |
which will cause the type X to be represented using a single pointer. When using this representation, the bounds are right behind the array. This representation is slightly less efficient, and does not allow quite such flexibility in the use of foreign pointers or in using the Unrestricted_Access attribute to create pointers to non-aliased objects. But for any standard portable use of the access type it will work in a functionally correct manner and allow porting of existing code. Note that another way of forcing a thin pointer representation is to use a component size clause for the element size in an array, or a record representation clause for an access field in a record.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The VMS version of GNAT fully implements all the pragmas and attributes provided by DEC Ada 83, as well as providing the standard DEC Ada 83 libraries, including Starlet. In addition, data layouts and parameter passing conventions are highly compatible. This means that porting existing DEC Ada 83 code to GNAT in VMS systems should be easier than most other porting efforts. The following are some of the most significant differences between GNAT and DEC Ada 83.
TO_ADDRESS (INTEGER) TO_ADDRESS (UNSIGNED_LONGWORD) TO_ADDRESS (universal_integer) |
The version of TO_ADDRESS taking a universal integer argument is in fact an extension to Ada 83 not strictly compatible with the reference manual. In GNAT, we are constrained to be exactly compatible with the standard, and this means we cannot provide this capability. In DEC Ada 83, the point of this definition is to deal with a call like:
TO_ADDRESS (16#12777#); |
Normally, according to the Ada 83 standard, one would expect this to be ambiguous, since it matches both the INTEGER and UNSIGNED_LONGWORD forms of TO_ADDRESS. However, in DEC Ada 83, there is no ambiguity, since the definition using universal_integer takes precedence.
In GNAT, since the version with universal_integer cannot be supplied, it is not possible to be 100% compatible. Since there are many programs using numeric constants for the argument to TO_ADDRESS, the decision in GNAT was to change the name of the function in the UNSIGNED_LONGWORD case, so the declarations provided in the GNAT version of AUX_Dec are:
function To_Address (X : Integer) return Address; pragma Pure_Function (To_Address); function To_Address_Long (X : Unsigned_Longword) return Address; pragma Pure_Function (To_Address_Long); |
This means that programs using TO_ADDRESS for UNSIGNED_LONGWORD must change the name to TO_ADDRESS_LONG.
For full details on these and other less significant compatibility issues, see appendix E of the Digital publication entitled DEC Ada, Technical Overview and Comparison on DIGITAL Platforms.
For GNAT running on other than VMS systems, all the DEC Ada 83 pragmas and attributes are recognized, although only a subset of them can sensibly be implemented. The description of pragmas in this reference manual indicates whether or not they are applicable to non-VMS systems.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |