Next: , Previous: Using gcc for Semantic Checking, Up: Switches for gcc


3.2.9 Compiling Different Versions of Ada

GNAT is primarily an Ada 95 compiler, but the switches described in this section allow operation in Ada 83 compatibility mode, and also allow the use of a preliminary implementation of many of the expected new features in Ada 2005, the forthcoming new version of the standard.
-gnat83 (Ada 83 Compatibility Mode)
Although GNAT is primarily an Ada 95 compiler, it accepts this switch to specify that an Ada 83 program is to be compiled in Ada 83 mode. If you specify this switch, GNAT rejects most Ada 95 extensions and applies Ada 83 semantics where this can be done easily. It is not possible to guarantee this switch does a perfect job; for example, some subtle tests, such as are found in earlier ACVC tests (and that have been removed from the ACATS suite for Ada 95), might not compile correctly. Nevertheless, this switch may be useful in some circumstances, for example where, due to contractual reasons, legacy code needs to be maintained using only Ada 83 features.

With few exceptions (most notably the need to use <> on unconstrained generic formal parameters, the use of the new Ada 95 reserved words, and the use of packages with optional bodies), it is not necessary to use the -gnat83 switch when compiling Ada 83 programs, because, with rare exceptions, Ada 95 is upwardly compatible with Ada 83. This means that a correct Ada 83 program is usually also a correct Ada 95 program. For further information, please refer to Compatibility and Porting Guide.

-gnat95 (Ada 95 mode)
GNAT is primarily an Ada 95 compiler, and all current releases of GNAT Pro compile in Ada 95 mode by default. Typically, Ada 95 is sufficiently upwards compatible with Ada 83, that legacy Ada 83 programs may be compiled using this default Ada95 mode without problems (see section above describing the use of -gnat83 to run in Ada 83 mode).

In Ada 95 mode, the use of Ada 2005 features will in general cause error messages or warnings. Some specialized releases of GNAT (notably the GAP academic version) operate in Ada 2005 mode by default (see section below describing the use of -gnat05 to run in Ada 2005 mode). For such versions the -gnat95 switch may be used to enforce Ada 95 mode. This option also can be used to cancel the effect of a previous -gnat83 or -gnat05 switch earlier in the command line.

-gnat05 (Ada 2005 mode)
Although GNAT is primarily an Ada 95 compiler, it can be set to operate in Ada 2005 mode using this option. Although the new standard has not yet been issued (as of early 2005), many features have been discussed and approved in “Ada Issues” (AI's). For the text of these AI's, see www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs. Included with GNAT releases is a file features-ada0y that describes the current set of implemented Ada 2005 features.

If these features are used in Ada 95 mode (which is the normal default), then error messages or warnings may be generated, reflecting the fact that these new features are otherwise unauthorized extensions to Ada 95. The use of the -gnat05 switch (or an equivalent pragma) causes these messages to be suppressed.

Note that some specialized releases of GNAT (notably the GAP academic version) have Ada 2005 mode on by default, and in such environments, the Ada 2005 features can be used freely without the use of switches.