GNAT GPL User's Guide: Compiling with gcc

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

# 3. Compiling with `gcc`

This chapter discusses how to compile Ada programs using the `gcc` command. It also describes the set of switches that can be used to control the behavior of the compiler.

> 3.1 Compiling Programs |  |
> 3.2 Switches for `gcc` |  |
> 3.3 Search Paths and the Run-Time Library (RTL) |  |
> 3.4 Order of Compilation Issues |  |
> 3.5 Examples |  |

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.1 Compiling Programs

The first step in creating an executable program is to compile the units of the program using the `gcc` command. You must compile the following files:

- the body file (``.adb'`) for a library level subprogram or generic subprogram

- the spec file (``.ads'`) for a library level package or generic package that has no body

- the body file (``.adb'`) for a library level package or generic package that has a body

You need not compile the following files

- the spec of a library unit which has a body

- subunits

because they are compiled as part of compiling related units. GNAT package specs when the corresponding body is compiled, and subunits when the parent is compiled.

If you attempt to compile any of these files, you will get one of the following error messages (where fff is the name of the file you compiled):

    cannot generate code for file fff (package spec)
    to check package spec, use -gnatc

    cannot generate code for file fff (missing subunits)
    to check parent unit, use -gnatc

    cannot generate code for file fff (subprogram spec)
    to check subprogram spec, use -gnatc

    cannot generate code for file fff (subunit)
    to check subunit, use -gnatc

As indicated by the above error messages, if you want to submit one of these files to the compiler to check for correct semantics without generating code, then use the ``-gnatc'` switch.

The basic command for compiling a file containing an Ada unit is

    $ gcc -c [switches] `file name'

where file name is the name of the Ada file (usually having an extension ``.ads'` for a spec or ``.adb'` for a body). You specify the ``-c'` switch to tell `gcc` to compile, but not link, the file. The result of a successful compilation is an object file, which has the same name as the source file but an extension of ``.o'` and an Ada Library Information (ALI) file, which also has the same name as the source file, but with ``.ali'` as the extension. GNAT creates these two output files in the current directory, but you may specify a source file in any directory using an absolute or relative path specification containing the directory information.

`gcc` is actually a driver program that looks at the extensions of the file arguments and loads the appropriate compiler. For example, the GNU C compiler is ``cc1'`, and the Ada compiler is ``gnat1'`. These programs are in directories known to the driver program (in some configurations via environment variables you set), but need not be in your path. The `gcc` driver also calls the assembler and any other utilities needed to complete the generation of the required object files.

It is possible to supply several file names on the same `gcc` command. This causes `gcc` to call the appropriate compiler for each file. For example, the following command lists two separate files to be compiled:

    $ gcc -c x.adb y.adb

calls `gnat1` (the Ada compiler) twice to compile ``x.adb'` and ``y.adb'`. The compiler generates two object files ``x.o'` and ``y.o'` and the two ALI files ``x.ali'` and ``y.ali'`. Any switches apply to all the files listed,

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.2 Switches for `gcc`

The `gcc` command accepts switches that control the compilation process. These switches are fully described in this section. First we briefly list all the switches, in alphabetical order, then we describe the switches in more detail in functionally grouped sections.

More switches exist for GCC than those documented here, especially for specific targets. However, their use is not recommended as they may change code generation in ways that are incompatible with the Ada run-time library, or can cause inconsistencies between compilation units.

> 3.2.1 Output and Error Message Control |  |
> 3.2.2 Warning Message Control |  |
> 3.2.3 Debugging and Assertion Control |  |
> 3.2.4 Validity Checking |  |
> 3.2.5 Style Checking |  |
> 3.2.6 Run-Time Checks |  |
> 3.2.7 Using `gcc` for Syntax Checking |  |
> 3.2.8 Using `gcc` for Semantic Checking |  |
> 3.2.9 Compiling Different Versions of Ada |  |
> 3.2.10 Character Set Control |  |
> 3.2.11 File Naming Control |  |
> 3.2.12 Subprogram Inlining Control |  |
> 3.2.13 Auxiliary Output Control |  |
> 3.2.14 Debugging Control |  |
> 3.2.15 Exception Handling Control |  |
> 3.2.16 Units to Sources Mapping Files |  |
> 3.2.17 Integrated Preprocessing |  |
> 3.2.18 Code Generation Control |  |

``-b target'`
  Compile your program to run on target, which is the name of a system configuration. You must have a GNAT cross-compiler built if target is not the same as your host system.

``-Bdir'`
  Load compiler executables (for example, `gnat1`, the Ada compiler) from dir instead of the default location. Only use this switch when multiple versions of the GNAT compiler are available. See section `Options for Directory Search' in Using the GNU Compiler Collection (GCC), for further details. You would normally use the ``-b'` or ``-V'` switch instead.

``-c'`
  Compile. Always use this switch when compiling Ada programs.

  Note: for some other languages when using `gcc`, notably in the case of C and C++, it is possible to use use `gcc` without a ``-c'` switch to compile and link in one step. In the case of GNAT, you cannot use this approach, because the binder must be run and `gcc` cannot be used to run the GNAT binder.

``-fcallgraph-info[=su,da]'`
  Makes the compiler output callgraph information for the program, on a per-file basis. The information is generated in the VCG format. It can be decorated with additional, per-node and/or per-edge information, if a list of comma-separated markers is additionally specified. When the su marker is specified, the callgraph is decorated with stack usage information; it is equivalent to ``-fstack-usage'`. When the da marker is specified, the callgraph is decorated with information about dynamically allocated objects.

``-fdump-scos'`
  Generates SCO (Source Coverage Obligation) information in the ALI file. This information is used by advanced coverage tools. See unit ``SCOs'` in the compiler sources for details in files ``scos.ads'` and ``scos.adb'`.

``-fdump-xref'`
  Generates cross reference information in GLI files for C and C++ sources. The GLI files have the same syntax as the ALI files for Ada, and can be used for source navigation in IDEs and on the command line using e.g. gnatxref and the ``--ext=gli'` switch.

``-flto[=n]'`
  Enables Link Time Optimization. This switch must be used in conjunction with the traditional ``-Ox'` switches and instructs the compiler to defer most optimizations until the link stage. The advantage of this approach is that the compiler can do a whole-program analysis and choose the best interprocedural optimization strategy based on a complete view of the program, instead of a fragmentary view with the usual approach. This can also speed up the compilation of huge programs and reduce the size of the final executable, compared with a per-unit compilation with full inlining across modules enabled with the ``-gnatn2'` switch. The drawback of this approach is that it may require much more memory. The switch, as well as the accompanying ``-Ox'` switches, must be specified both for the compilation and the link phases. If the n parameter is specified, the optimization and final code generation at link time are executed using n parallel jobs by means of an installed `make` program.

``-fno-inline'`
  Suppresses all inlining, even if other optimization or inlining switches are set. This includes suppression of inlining that results from the use of the pragma `Inline_Always`. Any occurrences of pragma `Inline` or `Inline_Always` are ignored, and ``-gnatn'` and ``-gnatN'` have no effects if this switch is present. Note that inlining can also be suppressed on a finer-grained basis with pragma `No_Inline`.

``-fno-inline-functions'`
  Suppresses automatic inlining of subprograms, which is enabled if ``-O3'` is used.

``-fno-inline-small-functions'`
  Suppresses automatic inlining of small subprograms, which is enabled if ``-O2'` is used.

``-fno-inline-functions-called-once'`
  Suppresses inlining of subprograms local to the unit and called once from within it, which is enabled if ``-O1'` is used.

``-fno-ivopts'`
  Suppresses high-level loop induction variable optimizations, which are enabled if ``-O1'` is used. These optimizations are generally profitable but, for some specific cases of loops with numerous uses of the iteration variable that follow a common pattern, they may end up destroying the regularity that could be exploited at a lower level and thus producing inferior code.

``-fno-strict-aliasing'`
  Causes the compiler to avoid assumptions regarding non-aliasing of objects of different types. See 7.1.8 Optimization and Strict Aliasing for details.

``-fstack-check'`
  Activates stack checking. See 24.1 Stack Overflow Checking for details.

``-fstack-usage'`
  Makes the compiler output stack usage information for the program, on a per-subprogram basis. See 24.2 Static Stack Usage Analysis for details.

``-g'`
  Generate debugging information. This information is stored in the object file and copied from there to the final executable file by the linker, where it can be read by the debugger. You must use the ``-g'` switch if you plan on using the debugger.

``-gnat83'`
  Enforce Ada 83 restrictions.

``-gnat95'`
  Enforce Ada 95 restrictions.

``-gnat05'`
  Allow full Ada 2005 features.

``-gnat2005'`
  Allow full Ada 2005 features (same as ``-gnat05'`)

``-gnat12'`

``-gnat2012'`
  Allow full Ada 2012 features (same as ``-gnat12'`)

``-gnata'`
  Assertions enabled. `Pragma Assert` and `pragma Debug` to be activated. Note that these pragmas can also be controlled using the configuration pragmas `Assertion_Policy` and `Debug_Policy`. It also activates pragmas `Check`, `Precondition`, and `Postcondition`. Note that these pragmas can also be controlled using the configuration pragma `Check_Policy`. In Ada 2012, it also activates all assertions defined in the RM as aspects: preconditions, postconditions, type invariants and (sub)type predicates. In all Ada modes, corresponding pragmas for type invariants and (sub)type predicates are also activated.

``-gnatA'`
  Avoid processing ``gnat.adc'`. If a ``gnat.adc'` file is present, it will be ignored.

``-gnatb'`
  Generate brief messages to ``stderr'` even if verbose mode set.

``-gnatB'`
  Assume no invalid (bad) values except for 'Valid attribute use (see section 3.2.4 Validity Checking).

``-gnatc'`
  Check syntax and semantics only (no code generation attempted). When the compiler is invoked by `gnatmake`, if the switch ``-gnatc'` is only given to the compiler (after ``-cargs'` or in package Compiler of the project file, `gnatmake` will fail because it will not find the object file after compilation. If `gnatmake` is called with ``-gnatc'` as a builder switch (before ``-cargs'` or in package Builder of the project file) then `gnatmake` will not fail because it will not look for the object files after compilation, and it will not try to build and link. This switch may not be given if a previous `-gnatR` switch has been given, since `-gnatR` requires that the code generator be called to complete determination of representation information.

``-gnatC'`
  Generate CodePeer intermediate format (no code generation attempted). This switch will generate an intermediate representation suitable for use by CodePeer (``.scil'` files). This switch is not compatible with code generation (it will, among other things, disable some switches such as -gnatn, and enable others such as -gnata).

``-gnatd'`
  Specify debug options for the compiler. The string of characters after the ``-gnatd'` specify the specific debug options. The possible characters are 0-9, a-z, A-Z, optionally preceded by a dot. See compiler source file ``debug.adb'` for details of the implemented debug options. Certain debug options are relevant to applications programmers, and these are documented at appropriate points in this users guide.

``-gnatD'`
  Create expanded source files for source level debugging. This switch also suppress generation of cross-reference information (see ``-gnatx'`). Note that this switch is not allowed if a previous -gnatR switch has been given, since these two switches are not compatible.

``-gnateA'`
  Check that the actual parameters of a subprogram call are not aliases of one another. To qualify as aliasing, the actuals must denote objects of a composite type, their memory locations must be identical or overlapping, and at least one of the corresponding formal parameters must be of mode OUT or IN OUT.

      type Rec_Typ is record
         Data : Integer := 0;
      end record;

      function Self (Val : Rec_Typ) return Rec_Typ is
      begin
         return Val;
      end Self;

      procedure Detect_Aliasing (Val_1 : in out Rec_Typ; Val_2 : Rec_Typ) is
      begin
         null;
      end Detect_Aliasing;

      Obj : Rec_Typ;

      Detect_Aliasing (Obj, Obj);
      Detect_Aliasing (Obj, Self (Obj));

  In the example above, the first call to `Detect_Aliasing` fails with a `Program_Error` at runtime because the actuals for `Val_1` and `Val_2` denote the same object. The second call executes without raising an exception because `Self(Obj)` produces an anonymous object which does not share the memory location of `Obj`.

``-gnatec=path'`
  Specify a configuration pragma file (the equal sign is optional) (see section 9.2 The Configuration Pragmas Files).

``-gnateC'`
  Generate CodePeer messages in a compiler-like format. This switch is only effective if ``-gnatcC'` is also specified and requires an installation of CodePeer.

``-gnated'`
  Disable atomic synchronization

``-gnateDsymbol[=value]'`
  Defines a symbol, associated with value, for preprocessing. (see section 3.2.17 Integrated Preprocessing).

``-gnateE'`
  Generate extra information in exception messages. In particular, display extra column information and the value and range associated with index and range check failures, and extra column information for access checks. In cases where the compiler is able to determine at compile time that a check will fail, it gives a warning, and the extra information is not produced at run time.

``-gnatef'`
  Display full source path name in brief error messages.

``-gnateF'`
  Check for overflow on all floating-point operations, including those for unconstrained predefined types. See description of pragma `Check_Float_Overflow` in GNAT RM.

``-gnateG'`
  Save result of preprocessing in a text file.

``-gnateinnn'`
  Set maximum number of instantiations during compilation of a single unit to nnn. This may be useful in increasing the default maximum of 8000 for the rare case when a single unit legitimately exceeds this limit.

``-gnateInnn'`
  Indicates that the source is a multi-unit source and that the index of the unit to compile is nnn. nnn needs to be a positive number and need to be a valid index in the multi-unit source.

``-gnatel'`
  This switch can be used with the static elaboration model to issue info messages showing where implicit `pragma Elaborate` and `pragma Elaborate_All` are generated. This is useful in diagnosing elaboration circularities caused by these implicit pragmas when using the static elaboration model. See See the section in this guide on elaboration checking for further details. These messages are not generated by default, and are intended only for temporary use when debugging circularity problems.

``-gnateL'`
  This switch turns off the info messages about implicit elaboration pragmas.

``-gnatem=path'`
  Specify a mapping file (the equal sign is optional) (see section 3.2.16 Units to Sources Mapping Files).

``-gnatep=file'`
  Specify a preprocessing data file (the equal sign is optional) (see section 3.2.17 Integrated Preprocessing).

``-gnateP'`
  Turn categorization dependency errors into warnings. Ada requires that units that WITH one another have compatible categories, for example a Pure unit cannot WITH a Preelaborate unit. If this switch is used, these errors become warnings (which can be ignored, or suppressed in the usual manner). This can be useful in some specialized circumstances such as the temporary use of special test software.

``-gnateS'`
  Synonym of ``-fdump-scos'`, kept for backwards compatibility.

``-gnatet=path'`
  Generate target dependent information. The format of the output file is described in the section about switch ``-gnateT'`.

``-gnateT=path'`
  Read target dependent information, such as endianness or sizes and alignments of base type. If this switch is passed, the default target dependent information of the compiler is replaced by the one read from the input file. This is used by tools other than the compiler, e.g. to do semantic analysis of programs that will run on some other target than the machine on which the tool is run.

  The following target dependent values should be defined, where `Nat` denotes a natural integer value, `Pos` denotes a positive integer value, and fields marked with a question mark are boolean fields, where a value of 0 is False, and a value of 1 is True:

      Bits_BE                    : Nat; -- Bits stored big-endian?
      Bits_Per_Unit              : Pos; -- Bits in a storage unit
      Bits_Per_Word              : Pos; -- Bits in a word
      Bytes_BE                   : Nat; -- Bytes stored big-endian?
      Char_Size                  : Pos; -- Standard.Character'Size
      Double_Float_Alignment     : Nat; -- Alignment of double float
      Double_Scalar_Alignment    : Nat; -- Alignment of double length scalar
      Double_Size                : Pos; -- Standard.Long_Float'Size
      Float_Size                 : Pos; -- Standard.Float'Size
      Float_Words_BE             : Nat; -- Float words stored big-endian?
      Int_Size                   : Pos; -- Standard.Integer'Size
      Long_Double_Size           : Pos; -- Standard.Long_Long_Float'Size
      Long_Long_Size             : Pos; -- Standard.Long_Long_Integer'Size
      Long_Size                  : Pos; -- Standard.Long_Integer'Size
      Maximum_Alignment          : Pos; -- Maximum permitted alignment
      Max_Unaligned_Field        : Pos; -- Maximum size for unaligned bit field
      Pointer_Size               : Pos; -- System.Address'Size
      Short_Enums                : Nat; -- Short foreign convention enums?
      Short_Size                 : Pos; -- Standard.Short_Integer'Size
      Strict_Alignment           : Nat; -- Strict alignment?
      System_Allocator_Alignment : Nat; -- Alignment for malloc calls
      Wchar_T_Size               : Pos; -- Interfaces.C.wchar_t'Size
      Words_BE                   : Nat; -- Words stored big-endian?

  The format of the input file is as follows. First come the values of the variables defined above, with one line per value:

      name  value

  where `name` is the name of the parameter, spelled out in full, and cased as in the above list, and `value` is an unsigned decimal integer. Two or more blanks separates the name from the value.

  All the variables must be present, in alphabetical order (i.e. the same order as the list above).

  Then there is a blank line to separate the two parts of the file. Then come the lines showing the floating-point types to be registered, with one line per registered mode:

      name  digs float_rep size alignment

  where `name` is the string name of the type (which can have single spaces embedded in the name (e.g. long double), `digs` is the number of digits for the floating-point type, `float_rep` is the float representation (I/V/A for IEEE-754-Binary, Vax_Native, AAMP), `size` is the size in bits, `alignment` is the alignment in bits. The name is followed by at least two blanks, fields are separated by at least one blank, and a LF character immediately follows the alignment field.

  Here is an example of a target parameterization file:

      Bits_BE                       0
      Bits_Per_Unit                 8
      Bits_Per_Word                64
      Bytes_BE                      0
      Char_Size                     8
      Double_Float_Alignment        0
      Double_Scalar_Alignment       0
      Double_Size                  64
      Float_Size                   32
      Float_Words_BE                0
      Int_Size                     64
      Long_Double_Size            128
      Long_Long_Size               64
      Long_Size                    64
      Maximum_Alignment            16
      Max_Unaligned_Field          64
      Pointer_Size                 64
      Short_Size                   16
      Strict_Alignment              0
      System_Allocator_Alignment   16
      Wchar_T_Size                 32
      Words_BE                      0

      float         15  I  64  64
      double        15  I  64  64
      long double   18  I  80 128
      TF            33  I 128 128

``-gnateu'`
  Ignore unrecognized validity, warning, and style switches that appear after this switch is given. This may be useful when compiling sources developed on a later version of the compiler with an earlier version. Of course the earlier version must support this switch.

``-gnateV'`
  Check that all actual parameters of a subprogram call are valid according to the rules of validity checking (see section 3.2.4 Validity Checking).

``-gnateY'`
  Ignore all STYLE_CHECKS pragmas. Full legality checks are still carried out, but the pragmas have no effect on what style checks are active. This allows all style checking options to be controlled from the command line.

``-gnatE'`
  Full dynamic elaboration checks.

``-gnatf'`
  Full errors. Multiple errors per line, all undefined references, do not attempt to suppress cascaded errors.

``-gnatF'`
  Externals names are folded to all uppercase.

``-gnatg'`
  Internal GNAT implementation mode. This should not be used for applications programs, it is intended only for use by the compiler and its run-time library. For documentation, see the GNAT sources. Note that ``-gnatg'` implies ``-gnatw.ge'` and ``-gnatyg'` so that all standard warnings and all standard style options are turned on. All warnings and style messages are treated as errors.

``-gnatG=nn'`
  List generated expanded code in source form.

``-gnath'`
  Output usage information. The output is written to ``stdout'`.

``-gnatic'`
  Identifier character set (c=1/2/3/4/8/9/p/f/n/w). For details of the possible selections for c, see 3.2.10 Character Set Control.

``-gnatI'`
  Ignore representation clauses. When this switch is used, representation clauses are treated as comments. This is useful when initially porting code where you want to ignore rep clause problems, and also for compiling foreign code (particularly for use with ASIS). The representation clauses that are ignored are: enumeration_representation_clause, record_representation_clause, and attribute_definition_clause for the following attributes: Address, Alignment, Bit_Order, Component_Size, Machine_Radix, Object_Size, Size, Small, Stream_Size, and Value_Size. Note that this option should be used only for compiling -- the code is likely to malfunction at run time.

  Note that when `-gnatct` is used to generate trees for input into `ASIS` tools, these representation clauses are removed from the tree and ignored. This means that the tool will not see them.

``-gnatjnn'`
  Reformat error messages to fit on nn character lines

``-gnatk=n'`
  Limit file names to n (1-999) characters (`k` = krunch).

``-gnatl'`
  Output full source listing with embedded error messages.

``-gnatL'`
  Used in conjunction with -gnatG or -gnatD to intersperse original source lines (as comment lines with line numbers) in the expanded source output.

``-gnatm=n'`
  Limit number of detected error or warning messages to n where n is in the range 1..999999. The default setting if no switch is given is 9999. If the number of warnings reaches this limit, then a message is output and further warnings are suppressed, but the compilation is continued. If the number of error messages reaches this limit, then a message is output and the compilation is abandoned. The equal sign here is optional. A value of zero means that no limit applies.

``-gnatn[12]'`
  Activate inlining for subprograms for which pragma `Inline` is specified. This inlining is performed by the GCC back-end. An optional digit sets the inlining level: 1 for moderate inlining across modules or 2 for full inlining across modules. If no inlining level is specified, the compiler will pick it based on the optimization level.

``-gnatN'`
  Activate front end inlining for subprograms for which pragma `Inline` is specified. This inlining is performed by the front end and will be visible in the ``-gnatG'` output.

  When using a gcc-based back end (in practice this means using any version of GNAT other than the JGNAT, .NET or GNAAMP versions), then the use of ``-gnatN'` is deprecated, and the use of ``-gnatn'` is preferred. Historically front end inlining was more extensive than the gcc back end inlining, but that is no longer the case.

``-gnato??'`
  Set default mode for handling generation of code to avoid intermediate arithmetic overflow. Here ``??`' is two digits, a single digit, or nothing. Each digit is one of the digits ``1`' through ``3`':

  - `1`: all intermediate overflows checked against base type (`STRICT`)
  - `2`: minimize intermediate overflows (`MINIMIZED`)
  - `3`: eliminate intermediate overflows (`ELIMINATED`)

  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.

  If no digits follow the ``-gnato'`, then it is equivalent to ``-gnato11'`, causing all intermediate overflows to be handled in strict mode.

  This switch also causes arithmetic overflow checking to be performed (as though pragma `Unsuppress (Overflow_Mode)` has been specified.

  The default if no option ``-gnato'` is given is that overflow handling is in `STRICT` mode (computations done using the base type), and that overflow checking is suppressed.

  Note that division by zero is a separate check that is not controlled by this switch (division by zero checking is on by default).

  See also D.3 Specifying the Desired Mode.

``-gnatp'`
  Suppress all checks. See 3.2.6 Run-Time Checks for details. This switch has no effect if cancelled by a subsequent ``-gnat-p'` switch.

``-gnat-p'`
  Cancel effect of previous ``-gnatp'` switch.

``-gnatP'`
  Enable polling. This is required on some systems (notably Windows NT) to obtain asynchronous abort and asynchronous transfer of control capability. See section `Pragma Polling' in GNAT Reference Manual, for full details.

``-gnatq'`
  Don't quit. Try semantics, even if parse errors.

``-gnatQ'`
  Don't quit. Generate ``ALI'` and tree files even if illegalities. Note that code generation is still suppressed in the presence of any errors, so even with ``-gnatQ'` no object file is generated.

``-gnatr'`
  Treat pragma Restrictions as Restriction_Warnings.

``-gnatR[0/1/2/3[s]]'`
  Output representation information for declared types and objects. Note that this switch is not allowed if a previous `-gnatD` switch has been given, since these two switches are not compatible.

``-gnatRm[s]'`
  Output convention and parameter passing mechanisms for all subprograms.

``-gnats'`
  Syntax check only.

``-gnatS'`
  Print package Standard.

``-gnatt'`
  Generate tree output file.

``-gnatTnnn'`
  All compiler tables start at nnn times usual starting size.

``-gnatu'`
  List units for this compilation.

``-gnatU'`
  Tag all error messages with the unique string "error:"

``-gnatv'`
  Verbose mode. Full error output with source lines to ``stdout'`.

``-gnatV'`
  Control level of validity checking (see section 3.2.4 Validity Checking).

``-gnatwxxx'`
  Warning mode where xxx is a string of option letters that denotes the exact warnings that are enabled or disabled (see section 3.2.2 Warning Message Control).

``-gnatWe'`
  Wide character encoding method (e=n/h/u/s/e/8).

``-gnatx'`
  Suppress generation of cross-reference information.

``-gnatX'`
  Enable GNAT implementation extensions and latest Ada version.

``-gnaty'`
  Enable built-in style checks (see section 3.2.5 Style Checking).

``-gnatzm'`
  Distribution stub generation and compilation (m=r/c for receiver/caller stubs).

``-Idir'`
  Direct GNAT to search the dir directory for source files needed by the current compilation (see section 3.3 Search Paths and the Run-Time Library (RTL)).

``-I-'`
  Except for the source file named in the command line, do not look for source files in the directory containing the source file named in the command line (see section 3.3 Search Paths and the Run-Time Library (RTL)).

``-mbig-switch'`
  This standard gcc switch causes the compiler to use larger offsets in its jump table representation for `case` statements. This may result in less efficient code, but is sometimes necessary (for example on HP-UX targets) in order to compile large and/or nested `case` statements.

``-o file'`
  This switch is used in `gcc` to redirect the generated object file and its associated ALI file. Beware of this switch with GNAT, because it may cause the object file and ALI file to have different names which in turn may confuse the binder and the linker.

``-nostdinc'`
  Inhibit the search of the default location for the GNAT Run Time Library (RTL) source files.

``-nostdlib'`
  Inhibit the search of the default location for the GNAT Run Time Library (RTL) ALI files.

``-O[n]'`
  n controls the optimization level.

  n = 0
    No optimization, the default setting if no ``-O'` appears

  n = 1
    Normal optimization, the default if you specify ``-O'` without an operand. A good compromise between code quality and compilation time.

  n = 2
    Extensive optimization, may improve execution time, possibly at the cost of substantially increased compilation time.

  n = 3
    Same as ``-O2'`, and also includes inline expansion for small subprograms in the same unit.

  n = s
    Optimize space usage

  See also 7.1.3 Optimization Levels.

``-pass-exit-codes'`
  Catch exit codes from the compiler and use the most meaningful as exit status.

``--RTS=rts-path'`
  Specifies the default location of the runtime library. Same meaning as the equivalent `gnatmake` flag (see section 6.2 Switches for `gnatmake`).

``-S'`
  Used in place of ``-c'` to cause the assembler source file to be generated, using ``.s'` as the extension, instead of the object file. This may be useful if you need to examine the generated assembly code.

``-fverbose-asm'`
  Used in conjunction with ``-S'` to cause the generated assembly code file to be annotated with variable names, making it significantly easier to follow.

``-v'`
  Show commands generated by the `gcc` driver. Normally used only for debugging purposes or if you need to be sure what version of the compiler you are executing.

``-V ver'`
  Execute ver version of the compiler. This is the `gcc` version, not the GNAT version.

``-w'`
  Turn off warnings generated by the back end of the compiler. Use of this switch also causes the default for front end warnings to be set to suppress (as though ``-gnatws'` had appeared at the start of the options).

You may combine a sequence of GNAT switches into a single switch. For example, the combined switch

    -gnatofi3

is equivalent to specifying the following sequence of switches:

    -gnato -gnatf -gnati3

The following restrictions apply to the combination of switches in this manner:

- The switch ``-gnatc'` if combined with other switches must come first in the string.

- The switch ``-gnats'` if combined with other switches must come first in the string.

- The switches

  ``-gnatzc'` and ``-gnatzr'` may not be combined with any other switches, and only one of them may appear in the command line.

- The switch ``-gnat-p'` may not be combined with any other switch.

- Once a "y" appears in the string (that is a use of the ``-gnaty'` switch), then all further characters in the switch are interpreted as style modifiers (see description of ``-gnaty'`).

- Once a "d" appears in the string (that is a use of the ``-gnatd'` switch), then all further characters in the switch are interpreted as debug flags (see description of ``-gnatd'`).

- Once a "w" appears in the string (that is a use of the ``-gnatw'` switch), then all further characters in the switch are interpreted as warning mode modifiers (see description of ``-gnatw'`).

- Once a "V" appears in the string (that is a use of the ``-gnatV'` switch), then all further characters in the switch are interpreted as validity checking options (see section 3.2.4 Validity Checking).

- Option "em", "ec", "ep", "l=" and "R" must be the last options in a combined list of options.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.1 Output and Error Message Control

The standard default format for error messages is called "brief format". Brief format messages are written to ``stderr'` (the standard error file) and have the following form:

    e.adb:3:04: Incorrect spelling of keyword "function"
    e.adb:4:20: ";" should be "is"

The first integer after the file name is the line number in the file, and the second integer is the column number within the line. `GPS` can parse the error messages and point to the referenced character. The following switches provide control over the error message format:

``-gnatv'`
  The v stands for verbose. The effect of this setting is to write long-format error messages to ``stdout'` (the standard output file. The same program compiled with the ``-gnatv'` switch would generate:

      3. funcion X (Q : Integer)
         |
      >>> Incorrect spelling of keyword "function"
      4. return Integer;
                       |
      >>> ";" should be "is"

  The vertical bar indicates the location of the error, and the ``>>>'` prefix can be used to search for error messages. When this switch is used the only source lines output are those with errors.

``-gnatl'`
  The `l` stands for list. This switch causes a full listing of the file to be generated. In the case where a body is compiled, the corresponding spec is also listed, along with any subunits. Typical output from compiling a package body ``p.adb'` might look like:

       Compiling: p.adb

           1. package body p is
           2.    procedure a;
           3.    procedure a is separate;
           4. begin
           5.    null
                     |
              >>> missing ";"

           6. end;

      Compiling: p.ads

           1. package p is
           2.    pragma Elaborate_Body
                                      |
              >>> missing ";"

           3. end p;

      Compiling: p-a.adb

           1. separate p
                      |
              >>> missing "("

           2. procedure a is
           3. begin
           4.    null
                     |
              >>> missing ";"

           5. end;

  When you specify the ``-gnatv'` or ``-gnatl'` switches and standard output is redirected, a brief summary is written to ``stderr'` (standard error) giving the number of error messages and warning messages generated.

``-gnatl=file'`
  This has the same effect as ``-gnatl'` except that the output is written to a file instead of to standard output. If the given name ``fname'` does not start with a period, then it is the full name of the file to be written. If ``fname'` is an extension, it is appended to the name of the file being compiled. For example, if file ``xyz.adb'` is compiled with ``-gnatl=.lst'`, then the output is written to file xyz.adb.lst.

``-gnatU'`
  This switch forces all error messages to be preceded by the unique string "error:". This means that error messages take a few more characters in space, but allows easy searching for and identification of error messages.

``-gnatb'`
  The `b` stands for brief. This switch causes GNAT to generate the brief format error messages to ``stderr'` (the standard error file) as well as the verbose format message or full listing (which as usual is written to ``stdout'` (the standard output file).

``-gnatm=n'`
  The `m` stands for maximum. n is a decimal integer in the range of 1 to 999999 and limits the number of error or warning messages to be generated. For example, using ``-gnatm2'` might yield

      e.adb:3:04: Incorrect spelling of keyword "function"
      e.adb:5:35: missing ".."
      fatal error: maximum number of errors detected
      compilation abandoned

  The default setting if no switch is given is 9999. If the number of warnings reaches this limit, then a message is output and further warnings are suppressed, but the compilation is continued. If the number of error messages reaches this limit, then a message is output and the compilation is abandoned. A value of zero means that no limit applies.

  Note that the equal sign is optional, so the switches ``-gnatm2'` and ``-gnatm=2'` are equivalent.

``-gnatf'`
  The `f` stands for full. Normally, the compiler suppresses error messages that are likely to be redundant. This switch causes all error messages to be generated. In particular, in the case of references to undefined variables. If a given variable is referenced several times, the normal format of messages is

      e.adb:7:07: "V" is undefined (more references follow)

  where the parenthetical comment warns that there are additional references to the variable `V`. Compiling the same program with the ``-gnatf'` switch yields

      e.adb:7:07: "V" is undefined
      e.adb:8:07: "V" is undefined
      e.adb:8:12: "V" is undefined
      e.adb:8:16: "V" is undefined
      e.adb:9:07: "V" is undefined
      e.adb:9:12: "V" is undefined

  The ``-gnatf'` switch also generates additional information for some error messages. Some examples are:

  - Details on possibly non-portable unchecked conversion
  - List possible interpretations for ambiguous calls
  - Additional details on incorrect parameters

``-gnatjnn'`
  In normal operation mode (or if ``-gnatj0'` is used), then error messages with continuation lines are treated as though the continuation lines were separate messages (and so a warning with two continuation lines counts as three warnings, and is listed as three separate messages).

  If the ``-gnatjnn'` switch is used with a positive value for nn, then messages are output in a different manner. A message and all its continuation lines are treated as a unit, and count as only one warning or message in the statistics totals. Furthermore, the message is reformatted so that no line is longer than nn characters.

``-gnatq'`
  The `q` stands for quit (really "don't quit"). In normal operation mode, the compiler first parses the program and determines if there are any syntax errors. If there are, appropriate error messages are generated and compilation is immediately terminated. This switch tells GNAT to continue with semantic analysis even if syntax errors have been found. This may enable the detection of more errors in a single run. On the other hand, the semantic analyzer is more likely to encounter some internal fatal error when given a syntactically invalid tree.

``-gnatQ'`
  In normal operation mode, the ``ALI'` file is not generated if any illegalities are detected in the program. The use of ``-gnatQ'` forces generation of the ``ALI'` file. This file is marked as being in error, so it cannot be used for binding purposes, but it does contain reasonably complete cross-reference information, and thus may be useful for use by tools (e.g., semantic browsing tools or integrated development environments) that are driven from the ``ALI'` file. This switch implies ``-gnatq'`, since the semantic phase must be run to get a meaningful ALI file.

  In addition, if ``-gnatt'` is also specified, then the tree file is generated even if there are illegalities. It may be useful in this case to also specify ``-gnatq'` to ensure that full semantic processing occurs. The resulting tree file can be processed by ASIS, for the purpose of providing partial information about illegal units, but if the error causes the tree to be badly malformed, then ASIS may crash during the analysis.

  When ``-gnatQ'` is used and the generated ``ALI'` file is marked as being in error, `gnatmake` will attempt to recompile the source when it finds such an ``ALI'` file, including with switch ``-gnatc'`.

  Note that ``-gnatQ'` has no effect if ``-gnats'` is specified, since ALI files are never generated if ``-gnats'` is set.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.2 Warning Message Control

In addition to error messages, which correspond to illegalities as defined in the Ada Reference Manual, the compiler detects two kinds of warning situations.

First, the compiler considers some constructs suspicious and generates a warning message to alert you to a possible error. Second, if the compiler detects a situation that is sure to raise an exception at run time, it generates a warning message. The following shows an example of warning messages:

    e.adb:4:24: warning: creation of object may raise Storage_Error
    e.adb:10:17: warning: static value out of range
    e.adb:10:17: warning: "Constraint_Error" will be raised at run time

GNAT considers a large number of situations as appropriate for the generation of warning messages. As always, warnings are not definite indications of errors. For example, if you do an out-of-range assignment with the deliberate intention of raising a `Constraint_Error` exception, then the warning that may be issued does not indicate an error. Some of the situations for which GNAT issues warnings (at least some of the time) are given in the following list. This list is not complete, and new warnings are often added to subsequent versions of GNAT. The list is intended to give a general idea of the kinds of warnings that are generated.

- Possible infinitely recursive calls

- Out-of-range values being assigned

- Possible order of elaboration problems

- Size not a multiple of alignment for a record type

- Assertions (pragma Assert) that are sure to fail

- Unreachable code

- Address clauses with possibly unaligned values, or where an attempt is made to overlay a smaller variable with a larger one.

- Fixed-point type declarations with a null range

- Direct_IO or Sequential_IO instantiated with a type that has access values

- Variables that are never assigned a value

- Variables that are referenced before being initialized

- Task entries with no corresponding `accept` statement

- Duplicate accepts for the same task entry in a `select`

- Objects that take too much storage

- Unchecked conversion between types of differing sizes

- Missing `return` statement along some execution path in a function

- Incorrect (unrecognized) pragmas

- Incorrect external names

- Allocation from empty storage pool

- Potentially blocking operation in protected type

- Suspicious parenthesization of expressions

- Mismatching bounds in an aggregate

- Attempt to return local value by reference

- Premature instantiation of a generic body

- Attempt to pack aliased components

- Out of bounds array subscripts

- Wrong length on string assignment

- Violations of style rules if style checking is enabled

- Unused `with` clauses

- `Bit_Order` usage that does not have any effect

- `Standard.Duration` used to resolve universal fixed expression

- Dereference of possibly null value

- Declaration that is likely to cause storage error

- Internal GNAT unit `with`'ed by application unit

- Values known to be out of range at compile time

- Unreferenced or unmodified variables. Note that a special exemption applies to variables which contain any of the substrings `DISCARD, DUMMY, IGNORE, JUNK, UNUSED`, in any casing. Such variables are considered likely to be intentionally used in a situation where otherwise a warning would be given, so warnings of this kind are always suppressed for such variables.

- Address overlays that could clobber memory

- Unexpected initialization when address clause present

- Bad alignment for address clause

- Useless type conversions

- Redundant assignment statements and other redundant constructs

- Useless exception handlers

- Accidental hiding of name by child unit

- Access before elaboration detected at compile time

- A range in a `for` loop that is known to be null or might be null

The following section lists compiler switches that are available to control the handling of warning messages. It is also possible to exercise much finer control over what warnings are issued and suppressed using the GNAT pragma Warnings, See section `Pragma Warnings' in GNAT Reference manual.

``-gnatwa'`
  Activate most optional warnings. This switch activates most optional warning messages. See the remaining list in this section for details on optional warning messages that can be individually controlled. The warnings that are not turned on by this switch are:

  ``-gnatwd'` (implicit dereferencing) ``-gnatw.d'` (tag warnings with -gnatw switch) ``-gnatwh'` (hiding) ``-gnatw.h'` (holes in record layouts) ``-gnatw.k'` (redefinition of names in standard) ``-gnatwl'` (elaboration warnings) ``-gnatw.l'` (inherited aspects) ``-gnatw.n'` (atomic synchronization) ``-gnatwo'` (address clause overlay) ``-gnatw.o'` (values set by out parameters ignored) ``-gnatw.s'` (overridden size clause) ``-gnatwt'` (tracking of deleted conditional code) ``-gnatw.u'` (unordered enumeration) ``-gnatw.w'` (use of Warnings Off) ``-gnatw.y'` (reasons for package needing body)

  All other optional warnings are turned on.

``-gnatwA'`
  Suppress all optional errors. This switch suppresses all optional warning messages, see remaining list in this section for details on optional warning messages that can be individually controlled. Note that unlike switch ``-gnatws'`, the use of switch ``-gnatwA'` does not suppress warnings that are normally given unconditionally and cannot be individually controlled (for example, the warning about a missing exit path in a function). Also, again unlike switch ``-gnatws'`, warnings suppressed by the use of switch ``-gnatwA'` can be individually turned back on. For example the use of switch ``-gnatwA'` followed by switch ``-gnatwd'` will suppress all optional warnings except the warnings for implicit dereferencing.

``-gnatw.a'`
  Activate warnings on failing assertions. This switch activates warnings for assertions where the compiler can tell at compile time that the assertion will fail. Note that this warning is given even if assertions are disabled. The default is that such warnings are generated.

``-gnatw.A'`
  Suppress warnings on failing assertions. This switch suppresses warnings for assertions where the compiler can tell at compile time that the assertion will fail.

``-gnatwb'`
  Activate warnings on bad fixed values. This switch activates warnings for static fixed-point expressions whose value is not an exact multiple of Small. Such values are implementation dependent, since an implementation is free to choose either of the multiples that surround the value. GNAT always chooses the closer one, but this is not required behavior, and it is better to specify a value that is an exact multiple, ensuring predictable execution. The default is that such warnings are not generated.

``-gnatwB'`
  Suppress warnings on bad fixed values. This switch suppresses warnings for static fixed-point expressions whose value is not an exact multiple of Small.

``-gnatw.b'`
  Activate warnings on biased representation. This switch activates warnings when a size clause, value size clause, component clause, or component size clause forces the use of biased representation for an integer type (e.g. representing a range of 10..11 in a single bit by using 0/1 to represent 10/11). The default is that such warnings are generated.

``-gnatw.B'`
  Suppress warnings on biased representation. This switch suppresses warnings for representation clauses that force the use of biased representation.

``-gnatwc'`
  Activate warnings on conditionals. This switch activates warnings for conditional expressions used in tests that are known to be True or False at compile time. The default is that such warnings are not generated. Note that this warning does not get issued for the use of boolean variables or constants whose values are known at compile time, since this is a standard technique for conditional compilation in Ada, and this would generate too many false positive warnings.

  This warning option also activates a special test for comparisons using the operators ">=" and" <=". If the compiler can tell that only the equality condition is possible, then it will warn that the ">" or "<" part of the test is useless and that the operator could be replaced by "=". An example would be comparing a `Natural` variable <= 0.

  This warning option also generates warnings if one or both tests is optimized away in a membership test for integer values if the result can be determined at compile time. Range tests on enumeration types are not included, since it is common for such tests to include an end point.

  This warning can also be turned on using ``-gnatwa'`.

``-gnatwC'`
  Suppress warnings on conditionals. This switch suppresses warnings for conditional expressions used in tests that are known to be True or False at compile time.

``-gnatw.c'`
  Activate warnings on missing component clauses. This switch activates warnings for record components where a record representation clause is present and has component clauses for the majority, but not all, of the components. A warning is given for each component for which no component clause is present.

``-gnatw.C'`
  Suppress warnings on missing component clauses. This switch suppresses warnings for record components that are missing a component clause in the situation described above.

``-gnatwd'`
  Activate warnings on implicit dereferencing. If this switch is set, then the use of a prefix of an access type in an indexed component, slice, or selected component without an explicit `.all` will generate a warning. With this warning enabled, access checks occur only at points where an explicit `.all` appears in the source code (assuming no warnings are generated as a result of this switch). The default is that such warnings are not generated.

``-gnatwD'`
  Suppress warnings on implicit dereferencing. This switch suppresses warnings for implicit dereferences in indexed components, slices, and selected components.

``-gnatw.d'`
  Activate tagging of warning and info messages. If this switch is set, then warning messages are tagged, with one of the following strings:

  ``[-gnatw?]'`
    Used to tag warnings controlled by the switch ``-gnatwx'` where x is a letter a-z.

  ``[-gnatw.?]'`
    Used to tag warnings controlled by the switch ``-gnatw.x'` where x is a letter a-z.

  ``[-gnatel]'`
    Used to tag elaboration information (info) messages generated when the static model of elaboration is used and the ``-gnatel'` switch is set.

  ``[restriction warning]'`
    Used to tag warning messages for restriction violations, activated by use of the pragma ``Restriction_Warnings'`.

  ``[warning-as-error]'`
    Used to tag warning messages that have been converted to error messages by use of the pragma Warning_As_Error. Note that such warnings are prefixed by the string "error: " rather than "warning: ".

  ``[enabled by default]'`
    Used to tag all other warnings that are always given by default, unless warnings are completely suppressed using pragma ``Warnings(Off)'` or the switch ``-gnatws'`.

``-gnatw.D'`
  Deactivate tagging of warning and info messages messages. If this switch is set, then warning messages return to the default mode in which warnings and info messages are not tagged as described above for `-gnatw.d`.

``-gnatwe'`
  Treat warnings and style checks as errors. This switch causes warning messages and style check messages to be treated as errors. The warning string still appears, but the warning messages are counted as errors, and prevent the generation of an object file. Note that this is the only -gnatw switch that affects the handling of style check messages.

``-gnatw.e'`
  Activate every optional warning This switch activates all optional warnings, including those which are not activated by `-gnatwa`. The use of this switch is not recommended for normal use. If you turn this switch on, it is almost certain that you will get large numbers of useless warnings. The warnings that are excluded from `-gnatwa` are typically highly specialized warnings that are suitable for use only in code that has been specifically designed according to specialized coding rules.

``-gnatwf'`
  Activate warnings on unreferenced formals. This switch causes a warning to be generated if a formal parameter is not referenced in the body of the subprogram. This warning can also be turned on using ``-gnatwu'`. The default is that these warnings are not generated.

``-gnatwF'`
  Suppress warnings on unreferenced formals. This switch suppresses warnings for unreferenced formal parameters. Note that the combination ``-gnatwu'` followed by ``-gnatwF'` has the effect of warning on unreferenced entities other than subprogram formals.

``-gnatwg'`
  Activate warnings on unrecognized pragmas. This switch causes a warning to be generated if an unrecognized pragma is encountered. Apart from issuing this warning, the pragma is ignored and has no effect. The default is that such warnings are issued (satisfying the Ada Reference Manual requirement that such warnings appear).

``-gnatwG'`
  Suppress warnings on unrecognized pragmas. This switch suppresses warnings for unrecognized pragmas.

``-gnatw.g'`
  Warnings used for GNAT sources This switch sets the warning categories that are used by the standard GNAT style. Currently this is equivalent to ``-gnatwAao.sI.C.V.X'` but more warnings may be added in the future without advanced notice.

``-gnatwh'`
  Activate warnings on hiding. This switch activates warnings on hiding declarations. A declaration is considered hiding if it is for a non-overloadable entity, and it declares an entity with the same name as some other entity that is directly or use-visible. The default is that such warnings are not generated.

``-gnatwH'`
  Suppress warnings on hiding. This switch suppresses warnings on hiding declarations.

``-gnatw.h'`
  Activate warnings on holes/gaps in records. This switch activates warnings on component clauses in record representation clauses that leave holes (gaps) in the record layout. If this warning option is active, then record representation clauses should specify a contiguous layout, adding unused fill fields if needed.

``-gnatw.H'`
  Suppress warnings on holes/gaps in records. This switch suppresses warnings on component clauses in record representation clauses that leave holes (haps) in the record layout.

``-gnatwi'`
  Activate warnings on implementation units. This switch activates warnings for a `with` of an internal GNAT implementation unit, defined as any unit from the `Ada`, `Interfaces`, `GNAT`, or `System` hierarchies that is not documented in either the Ada Reference Manual or the GNAT Programmer's Reference Manual. Such units are intended only for internal implementation purposes and should not be `with`'ed by user programs. The default is that such warnings are generated

``-gnatwI'`
  Disable warnings on implementation units. This switch disables warnings for a `with` of an internal GNAT implementation unit.

``-gnatw.i'`
  Activate warnings on overlapping actuals. This switch enables a warning on statically detectable overlapping actuals in a subprogram call, when one of the actuals is an in-out parameter, and the types of the actuals are not by-copy types. This warning is off by default.

``-gnatw.I'`
  Disable warnings on overlapping actuals. This switch disables warnings on overlapping actuals in a call..

``-gnatwj'`
  Activate warnings on obsolescent features (Annex J). If this warning option is activated, then warnings are generated for calls to subprograms marked with `pragma Obsolescent` and for use of features in Annex J of the Ada Reference Manual. In the case of Annex J, not all features are flagged. In particular use of the renamed packages (like `Text_IO`) and use of package `ASCII` are not flagged, since these are very common and would generate many annoying positive warnings. The default is that such warnings are not generated.

  In addition to the above cases, warnings are also generated for GNAT features that have been provided in past versions but which have been superseded (typically by features in the new Ada standard). For example, `pragma Ravenscar` will be flagged since its function is replaced by `pragma Profile(Ravenscar)`, and `pragma Interface_Name` will be flagged since its function is replaced by `pragma Import`.

  Note that this warning option functions differently from the restriction `No_Obsolescent_Features` in two respects. First, the restriction applies only to annex J features. Second, the restriction does flag uses of package `ASCII`.

``-gnatwJ'`
  Suppress warnings on obsolescent features (Annex J). This switch disables warnings on use of obsolescent features.

``-gnatwk'`
  Activate warnings on variables that could be constants. This switch activates warnings for variables that are initialized but never modified, and then could be declared constants. The default is that such warnings are not given.

``-gnatwK'`
  Suppress warnings on variables that could be constants. This switch disables warnings on variables that could be declared constants.

``-gnatw.k'`
  Activate warnings on redefinition of names in standard. This switch activates warnings for declarations that declare a name that is defined in package Standard. Such declarations can be confusing, especially since the names in package Standard continue to be directly visible, meaning that use visibiliy on such redeclared names does not work as expected. Names of discriminants and components in records are not included in this check.

``-gnatw.K'`
  Suppress warnings on variables that could be constants. This switch activates warnings for declarations that declare a name that is defined in package Standard.

``-gnatwl'`
  Activate warnings for elaboration pragmas. This switch activates warnings on missing for possible elaboration problems, including suspicious use of `Elaborate` pragmas, when using the static elaboration model, and possible situations that may raise `Program_Error` when using the dynamic elaboration model. See the section in this guide on elaboration checking for further details. The default is that such warnings are not generated.

``-gnatwL'`
  Suppress warnings for elaboration pragmas. This switch suppresses warnings for possible elaboration problems.

``-gnatw.l'`
  List inherited aspects. This switch causes the compiler to list inherited invariants, preconditions, and postconditions from Type_Invariant'Class, Invariant'Class, Pre'Class, and Post'Class aspects. Also list inherited subtype predicates.

``-gnatw.L'`
  Suppress listing of inherited aspects. This switch suppresses listing of inherited aspects.

``-gnatwm'`
  Activate warnings on modified but unreferenced variables. This switch activates warnings for variables that are assigned (using an initialization value or with one or more assignment statements) but whose value is never read. The warning is suppressed for volatile variables and also for variables that are renamings of other variables or for which an address clause is given. The default is that these warnings are not given.

``-gnatwM'`
  Disable warnings on modified but unreferenced variables. This switch disables warnings for variables that are assigned or initialized, but never read.

``-gnatw.m'`
  Activate warnings on suspicious modulus values. This switch activates warnings for modulus values that seem suspicious. The cases caught are where the size is the same as the modulus (e.g. a modulus of 7 with a size of 7 bits), and modulus values of 32 or 64 with no size clause. The guess in both cases is that 2**x was intended rather than x. In addition expressions of the form 2*x for small x generate a warning (the almost certainly accurate guess being that 2**x was intended). The default is that these warnings are given.

``-gnatw.M'`
  Disable warnings on suspicious modulus values. This switch disables warnings for suspicious modulus values.

``-gnatwn'`
  Set normal warnings mode. This switch sets normal warning mode, in which enabled warnings are issued and treated as warnings rather than errors. This is the default mode. the switch ``-gnatwn'` can be used to cancel the effect of an explicit ``-gnatws'` or ``-gnatwe'`. It also cancels the effect of the implicit ``-gnatwe'` that is activated by the use of ``-gnatg'`.

``-gnatw.n'`
  Activate warnings on atomic synchronization. This switch actives warnings when an access to an atomic variable requires the generation of atomic synchronization code. These warnings are off by default.
``-gnatw.N'`
  Suppress warnings on atomic synchronization. This switch suppresses warnings when an access to an atomic variable requires the generation of atomic synchronization code.

``-gnatwo'`
  Activate warnings on address clause overlays. This switch activates warnings for possibly unintended initialization effects of defining address clauses that cause one variable to overlap another. The default is that such warnings are generated.

``-gnatwO'`
  Suppress warnings on address clause overlays. This switch suppresses warnings on possibly unintended initialization effects of defining address clauses that cause one variable to overlap another.

``-gnatw.o'`
  Activate warnings on modified but unreferenced out parameters. This switch activates warnings for variables that are modified by using them as actuals for a call to a procedure with an out mode formal, where the resulting assigned value is never read. It is applicable in the case where there is more than one out mode formal. If there is only one out mode formal, the warning is issued by default (controlled by -gnatwu). The warning is suppressed for volatile variables and also for variables that are renamings of other variables or for which an address clause is given. The default is that these warnings are not given.

``-gnatw.O'`
  Disable warnings on modified but unreferenced out parameters. This switch suppresses warnings for variables that are modified by using them as actuals for a call to a procedure with an out mode formal, where the resulting assigned value is never read.

``-gnatwp'`
  Activate warnings on ineffective pragma Inlines. This switch activates warnings for failure of front end inlining (activated by ``-gnatN'`) to inline a particular call. There are many reasons for not being able to inline a call, including most commonly that the call is too complex to inline. The default is that such warnings are not given. Warnings on ineffective inlining by the gcc back-end can be activated separately, using the gcc switch -Winline.

``-gnatwP'`
  Suppress warnings on ineffective pragma Inlines. This switch suppresses warnings on ineffective pragma Inlines. If the inlining mechanism cannot inline a call, it will simply ignore the request silently.

``-gnatw.p'`
  Activate warnings on parameter ordering. This switch activates warnings for cases of suspicious parameter ordering when the list of arguments are all simple identifiers that match the names of the formals, but are in a different order. The warning is suppressed if any use of named parameter notation is used, so this is the appropriate way to suppress a false positive (and serves to emphasize that the "misordering" is deliberate). The default is that such warnings are not given.

``-gnatw.P'`
  Suppress warnings on parameter ordering. This switch suppresses warnings on cases of suspicious parameter ordering.

``-gnatwq'`
  Activate warnings on questionable missing parentheses. This switch activates warnings for cases where parentheses are not used and the result is potential ambiguity from a readers point of view. For example (not a > b) when a and b are modular means ((not a) > b) and very likely the programmer intended (not (a > b)). Similarly (-x mod 5) means (-(x mod 5)) and quite likely ((-x) mod 5) was intended. In such situations it seems best to follow the rule of always parenthesizing to make the association clear, and this warning switch warns if such parentheses are not present. The default is that these warnings are given.

``-gnatwQ'`
  Suppress warnings on questionable missing parentheses. This switch suppresses warnings for cases where the association is not clear and the use of parentheses is preferred.

``-gnatwr'`
  Activate warnings on redundant constructs. This switch activates warnings for redundant constructs. The following is the current list of constructs regarded as redundant:

  - Assignment of an item to itself.
  - Type conversion that converts an expression to its own type.
  - Use of the attribute `Base` where `typ'Base` is the same as `typ`.
  - Use of pragma `Pack` when all components are placed by a record representation clause.
  - Exception handler containing only a reraise statement (raise with no operand) which has no effect.
  - Use of the operator abs on an operand that is known at compile time to be non-negative
  - Comparison of boolean expressions to an explicit True value.

  The default is that warnings for redundant constructs are not given.

``-gnatwR'`
  Suppress warnings on redundant constructs. This switch suppresses warnings for redundant constructs.

``-gnatw.r'`
  Activate warnings for object renaming function. This switch activates warnings for an object renaming that renames a function call, which is equivalent to a constant declaration (as opposed to renaming the function itself). The default is that these warnings are given.

``-gnatw.R'`
  Suppress warnings for object renaming function. This switch suppresses warnings for object renaming function.

``-gnatws'`
  Suppress all warnings. This switch completely suppresses the output of all warning messages from the GNAT front end, including both warnings that can be controlled by switches described in this section, and those that are normally given unconditionally. The effect of this suppress action can only be cancelled by a subsequent use of the switch ``-gnatwn'`.

  Note that switch ``-gnatws'` does not suppress warnings from the `gcc` back end. To suppress these back end warnings as well, use the switch ``-w'` in addition to ``-gnatws'`. Also this switch has no effect on the handling of style check messages.

``-gnatw.s'`
  Activate warnings on overridden size clauses. This switch activates warnings on component clauses in record representation clauses where the length given overrides that specified by an explicit size clause for the component type. A warning is similarly given in the array case if a specified component size overrides an explicit size clause for the array component type.

``-gnatw.S'`
  Suppress warnings on overridden size clauses. This switch suppresses warnings on component clauses in record representation clauses that override size clauses, and similar warnings when an array component size overrides a size clause.

``-gnatwt'`
  Activate warnings for tracking of deleted conditional code. This switch activates warnings for tracking of code in conditionals (IF and CASE statements) that is detected to be dead code which cannot be executed, and which is removed by the front end. This warning is off by default. This may be useful for detecting deactivated code in certified applications.

``-gnatwT'`
  Suppress warnings for tracking of deleted conditional code. This switch suppresses warnings for tracking of deleted conditional code.

``-gnatw.t'`
  Activate warnings on suspicious contracts. This switch activates warnings on suspicious postconditions (whether a pragma `Postcondition` or a `Post` aspect in Ada 2012) and suspicious contract cases (pragma `Contract_Cases`). A function postcondition or contract case is suspicious when no postcondition or contract case for this function mentions the result of the function. A procedure postcondition or contract case is suspicious when it only refers to the pre-state of the procedure, because in that case it should rather be expressed as a precondition. The default is that such warnings are not generated.

``-gnatw.T'`
  Suppress warnings on suspicious contracts. This switch suppresses warnings on suspicious postconditions.

``-gnatwu'`
  Activate warnings on unused entities. This switch activates warnings to be generated for entities that are declared but not referenced, and for units that are `with`'ed and not referenced. In the case of packages, a warning is also generated if no entities in the package are referenced. This means that if a with'ed package is referenced but the only references are in `use` clauses or `renames` declarations, a warning is still generated. A warning is also generated for a generic package that is `with`'ed but never instantiated. In the case where a package or subprogram body is compiled, and there is a `with` on the corresponding spec that is only referenced in the body, a warning is also generated, noting that the `with` can be moved to the body. The default is that such warnings are not generated. This switch also activates warnings on unreferenced formals (it includes the effect of ``-gnatwf'`).

``-gnatwU'`
  Suppress warnings on unused entities. This switch suppresses warnings for unused entities and packages. It also turns off warnings on unreferenced formals (and thus includes the effect of ``-gnatwF'`).

``-gnatw.u'`
  Activate warnings on unordered enumeration types. This switch causes enumeration types to be considered as conceptually unordered, unless an explicit pragma `Ordered` is given for the type. The effect is to generate warnings in clients that use explicit comparisons or subranges, since these constructs both treat objects of the type as ordered. (A client is defined as a unit that is other than the unit in which the type is declared, or its body or subunits.) Please refer to the description of pragma `Ordered` in the GNAT GPL Reference Manual for further details. The default is that such warnings are not generated.

``-gnatw.U'`
  Deactivate warnings on unordered enumeration types. This switch causes all enumeration types to be considered as ordered, so that no warnings are given for comparisons or subranges for any type.

``-gnatwv'`
  Activate warnings on unassigned variables. This switch activates warnings for access to variables which may not be properly initialized. The default is that such warnings are generated.

``-gnatwV'`
  Suppress warnings on unassigned variables. This switch suppresses warnings for access to variables which may not be properly initialized. For variables of a composite type, the warning can also be suppressed in Ada 2005 by using a default initialization with a box. For example, if Table is an array of records whose components are only partially uninitialized, then the following code:

         Tab : Table := (others => <>);

  will suppress warnings on subsequent statements that access components of variable Tab.

``-gnatw.v'`
  Activate info messages for non-default bit order. This switch activates messages (labeled "info", they are not warnings, just informational messages) about the effects of non-default bit-order on records to which a component clause is applied. The effect of specifying non-default bit ordering is a bit subtle (and changed with Ada 2005), so these messages, which are given by default, are useful in understanding the exact consequences of using this feature.

``-gnatw.V'`
  Suppress info messages for non-default bit order. This switch suppresses information messages for the effects of specifying non-default bit order on record components with component clauses.

``-gnatww'`
  Activate warnings on wrong low bound assumption. This switch activates warnings for indexing an unconstrained string parameter with a literal or S'Length. This is a case where the code is assuming that the low bound is one, which is in general not true (for example when a slice is passed). The default is that such warnings are generated.

``-gnatwW'`
  Suppress warnings on wrong low bound assumption. This switch suppresses warnings for indexing an unconstrained string parameter with a literal or S'Length. Note that this warning can also be suppressed in a particular case by adding an assertion that the lower bound is 1, as shown in the following example.

         procedure K (S : String) is
            pragma Assert (S'First = 1);
            ...

``-gnatw.w'`
  Activate warnings on Warnings Off pragmas This switch activates warnings for use of `pragma Warnings (Off, entity)` where either the pragma is entirely useless (because it suppresses no warnings), or it could be replaced by `pragma Unreferenced` or `pragma Unmodified`. Also activates warnings for the case of Warnings (Off, String), where either there is no matching Warnings (On, String), or the Warnings (Off) did not suppress any warning. The default is that these warnings are not given.

``-gnatw.W'`
  Suppress warnings on unnecessary Warnings Off pragmas This switch suppresses warnings for use of `pragma Warnings (Off, ...)`.

``-gnatwx'`
  Activate warnings on Export/Import pragmas. This switch activates warnings on Export/Import pragmas when the compiler detects a possible conflict between the Ada and foreign language calling sequences. For example, the use of default parameters in a convention C procedure is dubious because the C compiler cannot supply the proper default, so a warning is issued. The default is that such warnings are generated.

``-gnatwX'`
  Suppress warnings on Export/Import pragmas. This switch suppresses warnings on Export/Import pragmas. The sense of this is that you are telling the compiler that you know what you are doing in writing the pragma, and it should not complain at you.

``-gnatw.x'`
  Activate warnings for No_Exception_Propagation mode. This switch activates warnings for exception usage when pragma Restrictions (No_Exception_Propagation) is in effect. Warnings are given for implicit or explicit exception raises which are not covered by a local handler, and for exception handlers which do not cover a local raise. The default is that these warnings are not given.

``-gnatw.X'`
  Disable warnings for No_Exception_Propagation mode. This switch disables warnings for exception usage when pragma Restrictions (No_Exception_Propagation) is in effect.

``-gnatwy'`
  Activate warnings for Ada compatibility issues. For the most part, newer versions of Ada are upwards compatible with older versions. For example, Ada 2005 programs will almost always work when compiled as Ada 2012. However there are some exceptions (for example the fact that `some` is now a reserved word in Ada 2012). This switch activates several warnings to help in identifying and correcting such incompatibilities. The default is that these warnings are generated. Note that at one point Ada 2005 was called Ada 0Y, hence the choice of character.

``-gnatwY'`
  Disable warnings for Ada compatibility issues. This switch suppresses the warnings intended to help in identifying incompatibilities between Ada language versions.

``-gnatw.y'`
  Activate information messages for why package spec needs body There are a number of cases in which a package spec needs a body. For example, the use of pragma Elaborate_Body, or the declaration of a procedure specification requiring a completion. This switch causes information messages to be output showing why a package specification requires a body. This can be useful in the case of a large package specification which is unexpectedly requiring a body. The default is that such information messages are not output.

``-gnatw.Y'`
  Disable information messages for why package spec needs body This switch suppresses the output of information messages showing why a package specification needs a body.

``-gnatwz'`
  Activate warnings on unchecked conversions. This switch activates warnings for unchecked conversions where the types are known at compile time to have different sizes. The default is that such warnings are generated. Warnings are also generated for subprogram pointers with different conventions, and, on VMS only, for data pointers with different conventions.

``-gnatwZ'`
  Suppress warnings on unchecked conversions. This switch suppresses warnings for unchecked conversions where the types are known at compile time to have different sizes or conventions.

``-gnatw.z'`
  Activate warnings for size not a multiple of alignment. This switch activates warnings for cases of record types with specified `Size` and `Alignment` attributes where the size is not a multiple of the alignment, resulting in an object size that is greater than the specified size. The default is that such warnings are generated.

``-gnatw.Z'`
  Suppress warnings for size not a multiple of alignment. This switch suppresses warnings for cases of record types with specified `Size` and `Alignment` attributes where the size is not a multiple of the alignment, resulting in an object size that is greater than the specified size. The warning can also be suppressed by giving an explicit `Object_Size` value.

``-Wunused'`
  The warnings controlled by the ``-gnatw'` switch are generated by the front end of the compiler. The ``GCC'` back end can provide additional warnings and they are controlled by the ``-W'` switch. For example, ``-Wunused'` activates back end warnings for entities that are declared but not referenced.

``-Wuninitialized'`
  Similarly, ``-Wuninitialized'` activates the back end warning for uninitialized variables. This switch must be used in conjunction with an optimization level greater than zero.

``-Wstack-usage=len'`
  Warn if the stack usage of a subprogram might be larger than len bytes. See 24.2 Static Stack Usage Analysis for details.

``-Wall'`
  This switch enables most warnings from the ``GCC'` back end. The code generator detects a number of warning situations that are missed by the ``GNAT'` front end, and this switch can be used to activate them. The use of this switch also sets the default front end warning mode to ``-gnatwa'`, that is, most front end warnings activated as well.

``-w'`
  Conversely, this switch suppresses warnings from the ``GCC'` back end. The use of this switch also sets the default front end warning mode to ``-gnatws'`, that is, front end warnings suppressed as well.

``-Werror'`
  This switch causes warnings from the ``GCC'` back end to be treated as errors. The warning string still appears, but the warning messages are counted as errors, and prevent the generation of an object file.

A string of warning parameters can be used in the same parameter. For example:

    -gnatwaGe

will turn on all optional warnings except for unrecognized pragma warnings, and also specify that warnings should be treated as errors.

When no switch ``-gnatw'` is used, this is equivalent to:

``-gnatw.a'`
``-gnatwB'`
``-gnatw.b'`
``-gnatwC'`
``-gnatw.C'`
``-gnatwD'`
``-gnatwF'`
``-gnatwg'`
``-gnatwH'`
``-gnatwi'`
``-gnatw.I'`
``-gnatwJ'`
``-gnatwK'`
``-gnatwL'`
``-gnatw.L'`
``-gnatwM'`
``-gnatw.m'`
``-gnatwn'`
``-gnatwo'`
``-gnatw.O'`
``-gnatwP'`
``-gnatw.P'`
``-gnatwq'`
``-gnatwR'`
``-gnatw.R'`
``-gnatw.S'`
``-gnatwT'`
``-gnatw.T'`
``-gnatwU'`
``-gnatwv'`
``-gnatww'`
``-gnatw.W'`
``-gnatwx'`
``-gnatw.X'`
``-gnatwy'`
``-gnatwz'`

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.3 Debugging and Assertion Control

``-gnata'`

  The pragmas `Assert` and `Debug` normally have no effect and are ignored. This switch, where ``a'` stands for assert, causes `Assert` and `Debug` pragmas to be activated.

  The pragmas have the form:

         pragma Assert (Boolean-expression [,
                            static-string-expression])
         pragma Debug (procedure call)

  The `Assert` pragma causes Boolean-expression to be tested. If the result is `True`, the pragma has no effect (other than possible side effects from evaluating the expression). If the result is `False`, the exception `Assert_Failure` declared in the package `System.Assertions` is raised (passing static-string-expression, if present, as the message associated with the exception). If no string expression is given the default is a string giving the file name and line number of the pragma.

  The `Debug` pragma causes procedure to be called. Note that `pragma Debug` may appear within a declaration sequence, allowing debugging procedures to be called between declarations.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.4 Validity Checking

The Ada Reference Manual defines the concept of invalid values (see RM 13.9.1). The primary source of invalid values is uninitialized variables. A scalar variable that is left uninitialized may contain an invalid value; the concept of invalid does not apply to access or composite types.

It is an error to read an invalid value, but the RM does not require run-time checks to detect such errors, except for some minimal checking to prevent erroneous execution (i.e. unpredictable behavior). This corresponds to the ``-gnatVd'` switch below, which is the default. For example, by default, if the expression of a case statement is invalid, it will raise Constraint_Error rather than causing a wild jump, and if an array index on the left-hand side of an assignment is invalid, it will raise Constraint_Error rather than overwriting an arbitrary memory location.

The ``-gnatVa'` may be used to enable additional validity checks, which are not required by the RM. These checks are often very expensive (which is why the RM does not require them). These checks are useful in tracking down uninitialized variables, but they are not usually recommended for production builds, and in particular we do not recommend using these extra validity checking options in combination with optimization, since this can confuse the optimizer. If performance is a consideration, leading to the need to optimize, then the validity checking options should not be used.

The other ``-gnatVx'` switches below allow finer-grained control; you can enable whichever validity checks you desire. However, for most debugging purposes, ``-gnatVa'` is sufficient, and the default ``-gnatVd'` (i.e. standard Ada behavior) is usually sufficient for non-debugging use.

The ``-gnatB'` switch tells the compiler to assume that all values are valid (that is, within their declared subtype range) except in the context of a use of the Valid attribute. This means the compiler can generate more efficient code, since the range of values is better known at compile time. However, an uninitialized variable can cause wild jumps and memory corruption in this mode.

The ``-gnatVx'` switch allows control over the validity checking mode as described below. The `x` argument is a string of letters that indicate validity checks that are performed or not performed in addition to the default checks required by Ada as described above.

``-gnatVa'`
  All validity checks. All validity checks are turned on. That is, ``-gnatVa'` is equivalent to ``gnatVcdfimorst'`.

``-gnatVc'`
  Validity checks for copies. The right hand side of assignments, and the initializing values of object declarations are validity checked.

``-gnatVd'`
  Default (RM) validity checks. Some validity checks are done by default following normal Ada semantics (RM 13.9.1 (9-11)). A check is done in case statements that the expression is within the range of the subtype. If it is not, Constraint_Error is raised. For assignments to array components, a check is done that the expression used as index is within the range. If it is not, Constraint_Error is raised. Both these validity checks may be turned off using switch ``-gnatVD'`. They are turned on by default. If ``-gnatVD'` is specified, a subsequent switch ``-gnatVd'` will leave the checks turned on. Switch ``-gnatVD'` should be used only if you are sure that all such expressions have valid values. If you use this switch and invalid values are present, then the program is erroneous, and wild jumps or memory overwriting may occur.

``-gnatVe'`
  Validity checks for elementary components. In the absence of this switch, assignments to record or array components are not validity checked, even if validity checks for assignments generally (``-gnatVc'`) are turned on. In Ada, assignment of composite values do not require valid data, but assignment of individual components does. So for example, there is a difference between copying the elements of an array with a slice assignment, compared to assigning element by element in a loop. This switch allows you to turn off validity checking for components, even when they are assigned component by component.

``-gnatVf'`
  Validity checks for floating-point values. In the absence of this switch, validity checking occurs only for discrete values. If ``-gnatVf'` is specified, then validity checking also applies for floating-point values, and NaNs and infinities are considered invalid, as well as out of range values for constrained types. Note that this means that standard IEEE infinity mode is not allowed. The exact contexts in which floating-point values are checked depends on the setting of other options. For example, ``-gnatVif'` or ``-gnatVfi'` (the order does not matter) specifies that floating-point parameters of mode `in` should be validity checked.

``-gnatVi'`
  Validity checks for `in` mode parameters Arguments for parameters of mode `in` are validity checked in function and procedure calls at the point of call.

``-gnatVm'`
  Validity checks for `in out` mode parameters. Arguments for parameters of mode `in out` are validity checked in procedure calls at the point of call. The `'m'` here stands for modify, since this concerns parameters that can be modified by the call. Note that there is no specific option to test `out` parameters, but any reference within the subprogram will be tested in the usual manner, and if an invalid value is copied back, any reference to it will be subject to validity checking.

``-gnatVn'`
  No validity checks. This switch turns off all validity checking, including the default checking for case statements and left hand side subscripts. Note that the use of the switch ``-gnatp'` suppresses all run-time checks, including validity checks, and thus implies ``-gnatVn'`. When this switch is used, it cancels any other ``-gnatV'` previously issued.

``-gnatVo'`
  Validity checks for operator and attribute operands. Arguments for predefined operators and attributes are validity checked. This includes all operators in package `Standard`, the shift operators defined as intrinsic in package `Interfaces` and operands for attributes such as `Pos`. Checks are also made on individual component values for composite comparisons, and on the expressions in type conversions and qualified expressions. Checks are also made on explicit ranges using ``..'` (e.g. slices, loops etc).

``-gnatVp'`
  Validity checks for parameters. This controls the treatment of parameters within a subprogram (as opposed to ``-gnatVi'` and ``-gnatVm'` which control validity testing of parameters on a call. If either of these call options is used, then normally an assumption is made within a subprogram that the input arguments have been validity checking at the point of call, and do not need checking again within a subprogram). If ``-gnatVp'` is set, then this assumption is not made, and parameters are not assumed to be valid, so their validity will be checked (or rechecked) within the subprogram.

``-gnatVr'`
  Validity checks for function returns. The expression in `return` statements in functions is validity checked.

``-gnatVs'`
  Validity checks for subscripts. All subscripts expressions are checked for validity, whether they appear on the right side or left side (in default mode only left side subscripts are validity checked).

``-gnatVt'`
  Validity checks for tests. Expressions used as conditions in `if`, `while` or `exit` statements are checked, as well as guard expressions in entry calls.

The ``-gnatV'` switch may be followed by a string of letters to turn on a series of validity checking options. For example, ``-gnatVcr'` specifies that in addition to the default validity checking, copies and function return expressions are to be validity checked. In order to make it easier to specify the desired combination of effects, the upper case letters `CDFIMORST` may be used to turn off the corresponding lower case option. Thus ``-gnatVaM'` turns on all validity checking options except for checking of `in out` procedure arguments.

The specification of additional validity checking generates extra code (and in the case of ``-gnatVa'` the code expansion can be substantial). However, these additional checks can be very useful in detecting uninitialized variables, incorrect use of unchecked conversion, and other errors leading to invalid values. The use of pragma `Initialize_Scalars` is useful in conjunction with the extra validity checking, since this ensures that wherever possible uninitialized variables have invalid values.

See also the pragma `Validity_Checks` which allows modification of the validity checking mode at the program source level, and also allows for temporary disabling of validity checks.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.5 Style Checking

The ``-gnatyx'` switch causes the compiler to enforce specified style rules. A limited set of style rules has been used in writing the GNAT sources themselves. This switch allows user programs to activate all or some of these checks. If the source program fails a specified style check, an appropriate message is given, preceded by the character sequence "(style)". This message does not prevent successful compilation (unless the ``-gnatwe'` switch is used).

Note that this is by no means intended to be a general facility for checking arbitrary coding standards. It is simply an embedding of the style rules we have chosen for the GNAT sources. If you are starting a project which does not have established style standards, you may find it useful to adopt the entire set of GNAT coding standards, or some subset of them. If you already have an established set of coding standards, then the selected style checking options may indeed correspond to choices you have made, but for general checking of an existing set of coding rules, you should look to the gnatcheck tool, which is designed for that purpose.

The string x is a sequence of letters or digits indicating the particular style checks to be performed. The following checks are defined:

``0-9'`
  Specify indentation level. If a digit from 1-9 appears in the string after ``-gnaty'` then proper indentation is checked, with the digit indicating the indentation level required. A value of zero turns off this style check. The general style of required indentation is as specified by the examples in the Ada Reference Manual. Full line comments must be aligned with the `--` starting on a column that is a multiple of the alignment level, or they may be aligned the same way as the following non-blank line (this is useful when full line comments appear in the middle of a statement, or they may be aligned with the source line on the previous non-blank line.

``a'`
  Check attribute casing. Attribute names, including the case of keywords such as `digits` used as attributes names, must be written in mixed case, that is, the initial letter and any letter following an underscore must be uppercase. All other letters must be lowercase.

``A'`
  Use of array index numbers in array attributes. When using the array attributes First, Last, Range, or Length, the index number must be omitted for one-dimensional arrays and is required for multi-dimensional arrays.

``b'`
  Blanks not allowed at statement end. Trailing blanks are not allowed at the end of statements. The purpose of this rule, together with h (no horizontal tabs), is to enforce a canonical format for the use of blanks to separate source tokens.

``B'`
  Check Boolean operators. The use of AND/OR operators is not permitted except in the cases of modular operands, array operands, and simple stand-alone boolean variables or boolean constants. In all other cases `and then`/`or else` are required.

``c'`
  Check comments, double space. Comments must meet the following set of rules:

  - The "`--`" that starts the column must either start in column one, or else at least one blank must precede this sequence.

  - Comments that follow other tokens on a line must have at least one blank following the "`--`" at the start of the comment.

  - Full line comments must have at least two blanks following the "`--`" that starts the comment, with the following exceptions.

  - A line consisting only of the "`--`" characters, possibly preceded by blanks is permitted.

  - A comment starting with "`--x`" where `x` is a special character is permitted. This allows proper processing of the output generated by specialized tools including `gnatprep` (where "`--!`" is used) and the SPARK annotation language (where "`--#`" is used). For the purposes of this rule, a special character is defined as being in one of the ASCII ranges `16#21#...16#2F#` or `16#3A#...16#3F#`. Note that this usage is not permitted in GNAT implementation units (i.e., when ``-gnatg'` is used).

  - A line consisting entirely of minus signs, possibly preceded by blanks, is permitted. This allows the construction of box comments where lines of minus signs are used to form the top and bottom of the box.

  - A comment that starts and ends with "`--`" is permitted as long as at least one blank follows the initial "`--`". Together with the preceding rule, this allows the construction of box comments, as shown in the following example:

        ---------------------------
        -- This is a box comment --
        -- with two text lines.  --
        ---------------------------

``C'`
  Check comments, single space. This is identical to `c` except that only one space is required following the `--` of a comment instead of two.

``d'`
  Check no DOS line terminators present. All lines must be terminated by a single ASCII.LF character (in particular the DOS line terminator sequence CR/LF is not allowed).

``e'`
  Check end/exit labels. Optional labels on `end` statements ending subprograms and on `exit` statements exiting named loops, are required to be present.

``f'`
  No form feeds or vertical tabs. Neither form feeds nor vertical tab characters are permitted in the source text.

``g'`
  GNAT style mode. The set of style check switches is set to match that used by the GNAT sources. This may be useful when developing code that is eventually intended to be incorporated into GNAT. Currently this is equivalent to ``-gnatwydISux'`) but additional style switches may be added to this set in the future without advance notice.

``h'`
  No horizontal tabs. Horizontal tab characters are not permitted in the source text. Together with the b (no blanks at end of line) check, this enforces a canonical form for the use of blanks to separate source tokens.

``i'`
  Check if-then layout. The keyword `then` must appear either on the same line as corresponding `if`, or on a line on its own, lined up under the `if`.

``I'`
  check mode IN keywords. Mode `in` (the default mode) is not allowed to be given explicitly. `in out` is fine, but not `in` on its own.

``k'`
  Check keyword casing. All keywords must be in lower case (with the exception of keywords such as `digits` used as attribute names to which this check does not apply).

``l'`
  Check layout. Layout of statement and declaration constructs must follow the recommendations in the Ada Reference Manual, as indicated by the form of the syntax rules. For example an `else` keyword must be lined up with the corresponding `if` keyword.

  There are two respects in which the style rule enforced by this check option are more liberal than those in the Ada Reference Manual. First in the case of record declarations, it is permissible to put the `record` keyword on the same line as the `type` keyword, and then the `end` in `end record` must line up under `type`. This is also permitted when the type declaration is split on two lines. For example, any of the following three layouts is acceptable:

      type q is record
         a : integer;
         b : integer;
      end record;

      type q is
         record
            a : integer;
            b : integer;
         end record;

      type q is
         record
            a : integer;
            b : integer;
      end record;

  Second, in the case of a block statement, a permitted alternative is to put the block label on the same line as the `declare` or `begin` keyword, and then line the `end` keyword up under the block label. For example both the following are permitted:

      Block : declare
         A : Integer := 3;
      begin
         Proc (A, A);
      end Block;

      Block :
         declare
            A : Integer := 3;
         begin
            Proc (A, A);
         end Block;

  The same alternative format is allowed for loops. For example, both of the following are permitted:

      Clear : while J < 10 loop
         A (J) := 0;
      end loop Clear;

      Clear :
         while J < 10 loop
            A (J) := 0;
         end loop Clear;

``Lnnn'`
  Set maximum nesting level. The maximum level of nesting of constructs (including subprograms, loops, blocks, packages, and conditionals) may not exceed the given value ``nnn'`. A value of zero disconnects this style check.

``m'`
  Check maximum line length. The length of source lines must not exceed 79 characters, including any trailing blanks. The value of 79 allows convenient display on an 80 character wide device or window, allowing for possible special treatment of 80 character lines. Note that this count is of characters in the source text. This means that a tab character counts as one character in this count and a wide character sequence counts as a single character (however many bytes are needed in the encoding).

``Mnnn'`
  Set maximum line length. The length of lines must not exceed the given value ``nnn'`. The maximum value that can be specified is 32767. If neither style option for setting the line length is used, then the default is 255. This also controls the maximum length of lexical elements, where the only restriction is that they must fit on a single line.

``n'`
  Check casing of entities in Standard. Any identifier from Standard must be cased to match the presentation in the Ada Reference Manual (for example, `Integer` and `ASCII.NUL`).

``N'`
  Turn off all style checks. All style check options are turned off.

``o'`
  Check order of subprogram bodies. All subprogram bodies in a given scope (e.g. a package body) must be in alphabetical order. The ordering rule uses normal Ada rules for comparing strings, ignoring casing of letters, except that if there is a trailing numeric suffix, then the value of this suffix is used in the ordering (e.g. Junk2 comes before Junk10).

``O'`
  Check that overriding subprograms are explicitly marked as such. The declaration of a primitive operation of a type extension that overrides an inherited operation must carry an overriding indicator.

``p'`
  Check pragma casing. Pragma names must be written in mixed case, that is, the initial letter and any letter following an underscore must be uppercase. All other letters must be lowercase. An exception is that SPARK_Mode is allowed as an alternative for Spark_Mode.

``r'`
  Check references. All identifier references must be cased in the same way as the corresponding declaration. No specific casing style is imposed on identifiers. The only requirement is for consistency of references with declarations.

``s'`
  Check separate specs. Separate declarations ("specs") are required for subprograms (a body is not allowed to serve as its own declaration). The only exception is that parameterless library level procedures are not required to have a separate declaration. This exception covers the most frequent form of main program procedures.

``S'`
  Check no statements after `then`/`else`. No statements are allowed on the same line as a `then` or `else` keyword following the keyword in an `if` statement. `or else` and `and then` are not affected, and a special exception allows a pragma to appear after `else`.

``t'`
  Check token spacing. The following token spacing rules are enforced:

  - The keywords `abs` and `not` must be followed by a space.

  - The token `=>` must be surrounded by spaces.

  - The token `<>` must be preceded by a space or a left parenthesis.

  - Binary operators other than `**` must be surrounded by spaces. There is no restriction on the layout of the `**` binary operator.

  - Colon must be surrounded by spaces.

  - Colon-equal (assignment, initialization) must be surrounded by spaces.

  - Comma must be the first non-blank character on the line, or be immediately preceded by a non-blank character, and must be followed by a space.

  - If the token preceding a left parenthesis ends with a letter or digit, then a space must separate the two tokens.

  - if the token following a right parenthesis starts with a letter or digit, then a space must separate the two tokens.

  - A right parenthesis must either be the first non-blank character on a line, or it must be preceded by a non-blank character.

  - A semicolon must not be preceded by a space, and must not be followed by a non-blank character.

  - A unary plus or minus may not be followed by a space.

  - A vertical bar must be surrounded by spaces.

``'`
  Exactly one blank (and no other white space) must appear between a `not` token and a following `in` token.

``u'`
  Check unnecessary blank lines. Unnecessary blank lines are not allowed. A blank line is considered unnecessary if it appears at the end of the file, or if more than one blank line occurs in sequence.

``x'`
  Check extra parentheses. Unnecessary extra level of parentheses (C-style) are not allowed around conditions in `if` statements, `while` statements and `exit` statements.

``y'`
  Set all standard style check options This is equivalent to `gnaty3aAbcefhiklmnprst`, that is all checking options enabled with the exception of ``-gnatyB'`, ``-gnatyd'`, ``-gnatyI'`, ``-gnatyLnnn'`, ``-gnatyo'`, ``-gnatyO'`, ``-gnatyS'`, ``-gnatyu'`, and ``-gnatyx'`.

``-'`
  Remove style check options This causes any subsequent options in the string to act as canceling the corresponding style check option. To cancel maximum nesting level control, use ``L'` parameter witout any integer value after that, because any digit following ``-'` in the parameter string of the ``-gnaty'` option will be threated as canceling indentation check. The same is true for ``M'` parameter. ``y'` and ``N'` parameters are not allowed after ``-'`.

``+'`
  This causes any subsequent options in the string to enable the corresponding style check option. That is, it cancels the effect of a previous -, if any.

In the above rules, appearing in column one is always permitted, that is, counts as meeting either a requirement for a required preceding space, or as meeting a requirement for no preceding space.

Appearing at the end of a line is also always permitted, that is, counts as meeting either a requirement for a following space, or as meeting a requirement for no following space.

If any of these style rules is violated, a message is generated giving details on the violation. The initial characters of such messages are always "`(style)`". Note that these messages are treated as warning messages, so they normally do not prevent the generation of an object file. The ``-gnatwe'` switch can be used to treat warning messages, including style messages, as fatal errors.

The switch ``-gnaty'` on its own (that is not followed by any letters or digits) is equivalent to the use of ``-gnatyy'` as described above, that is all built-in standard style check options are enabled.

The switch ``-gnatyN'` clears any previously set style checks.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.6 Run-Time Checks

By default, the following checks are suppressed: integer overflow checks, stack overflow checks, and checks for access before elaboration on subprogram calls. All other checks, including range checks and array bounds checks, are turned on by default. The following `gcc` switches refine this default behavior.

``-gnatp'`
  This switch causes the unit to be compiled as though `pragma Suppress (All_checks)` had been present in the source. Validity checks are also eliminated (in other words ``-gnatp'` also implies ``-gnatVn'`. Use this switch to improve the performance of the code at the expense of safety in the presence of invalid data or program bugs.

  Note that when checks are suppressed, the compiler is allowed, but not required, to omit the checking code. If the run-time cost of the checking code is zero or near-zero, the compiler will generate it even if checks are suppressed. In particular, if the compiler can prove that a certain check will necessarily fail, it will generate code to do an unconditional "raise", even if checks are suppressed. The compiler warns in this case. Another case in which checks may not be eliminated is when they are embedded in certain run time routines such as math library routines.

  Of course, run-time checks are omitted whenever the compiler can prove that they will not fail, whether or not checks are suppressed.

  Note that if you suppress a check that would have failed, program execution is erroneous, which means the behavior is totally unpredictable. The program might crash, or print wrong answers, or do anything else. It might even do exactly what you wanted it to do (and then it might start failing mysteriously next week or next year). The compiler will generate code based on the assumption that the condition being checked is true, which can result in erroneous execution if that assumption is wrong.

  The checks subject to suppression include all the checks defined by the Ada standard, the additional implementation defined checks `Alignment_Check`, `Duplicated_Tag_Check`, `Predicate_Check`, and `Validity_Check`, as well as any checks introduced using `pragma Check_Name`. Note that `Atomic_Synchronization` is not automatically suppressed by use of this option.

  If the code depends on certain checks being active, you can use pragma `Unsuppress` either as a configuration pragma or as a local pragma to make sure that a specified check is performed even if ``gnatp'` is specified.

  The ``-gnatp'` switch has no effect if a subsequent ``-gnat-p'` switch appears.

``-gnat-p'`
  This switch cancels the effect of a previous ``gnatp'` switch.

``-gnato??'`
  This switch controls the mode used for computing intermediate arithmetic integer operations, and also enables overflow checking. For a full description of overflow mode and checking control, see the "Overflow Check Handling in GNAT" appendix in this User's Guide.

  Overflow checks are always enabled by this switch. The argument controls the mode, using the codes

  - 1 = STRICT In STRICT mode, intermediate operations are always done using the base type, and overflow checking ensures that the result is within the base type range.

  - 2 = MINIMIZED In MINIMIZED mode, overflows in intermediate operations are avoided where possible by using a larger integer type for the computation (typically `Long_Long_Integer`). Overflow checking ensures that the result fits in this larger integer type.

  - 3 = ELIMINATED In ELIMINATED mode, overflows in intermediate operations are avoided by using multi-precision arithmetic. In this case, overflow checking has no effect on intermediate operations (since overflow is impossible).

  If two digits are present after ``-gnato'` then the first digit sets the mode for expressions outside assertions, and the second digit sets the mode for expressions within assertions. Here assertions is used in the technical sense (which includes for example precondition and postcondition expressions).

  If one digit is present, the corresponding mode is applicable to both expressions within and outside assertion expressions.

  If no digits are present, the default is to enable overflow checks and set STRICT mode for both kinds of expressions. This is compatible with the use of ``-gnato'` in previous versions of GNAT.

  Note that the ``-gnato??'` switch does not affect the code generated for any floating-point operations; it applies only to integer semantics. For floating-point, GNAT GPL has the `Machine_Overflows` attribute set to `False` and the normal mode of operation is to generate IEEE NaN and infinite values on overflow or invalid operations (such as dividing 0.0 by 0.0).

  The reason that we distinguish overflow checking from other kinds of range constraint checking is that a failure of an overflow check, unlike for example the failure of a range check, can result in an incorrect value, but cannot cause random memory destruction (like an out of range subscript), or a wild jump (from an out of range case value). Overflow checking is also quite expensive in time and space, since in general it requires the use of double length arithmetic.

  Note again that the default is ``-gnato00'`, so overflow checking is not performed in default mode. This means that out of the box, with the default settings, GNAT GPL does not do all the checks expected from the language description in the Ada Reference Manual. If you want all constraint checks to be performed, as described in this Manual, then you must explicitly use the ``-gnato??'` switch either on the `gnatmake` or `gcc` command.

``-gnatE'`
  Enables dynamic checks for access-before-elaboration on subprogram calls and generic instantiations. Note that ``-gnatE'` is not necessary for safety, because in the default mode, GNAT ensures statically that the checks would not fail. For full details of the effect and use of this switch, See section 3. Compiling with `gcc`.

``-fstack-check'`
  Activates stack overflow checking. For full details of the effect and use of this switch see 24.1 Stack Overflow Checking.

The setting of these switches only controls the default setting of the checks. You may modify them using either `Suppress` (to remove checks) or `Unsuppress` (to add back suppressed checks) pragmas in the program source.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.7 Using `gcc` for Syntax Checking

``-gnats'`

  The `s` stands for "syntax".

  Run GNAT in syntax checking only mode. For example, the command

      $ gcc -c -gnats x.adb

  compiles file ``x.adb'` in syntax-check-only mode. You can check a series of files in a single command , and can use wild cards to specify such a group of files. Note that you must specify the ``-c'` (compile only) flag in addition to the ``-gnats'` flag. . You may use other switches in conjunction with ``-gnats'`. In particular, ``-gnatl'` and ``-gnatv'` are useful to control the format of any generated error messages.

  When the source file is empty or contains only empty lines and/or comments, the output is a warning:

      $ gcc -c -gnats -x ada toto.txt
      toto.txt:1:01: warning: empty file, contains no compilation units
      $

  Otherwise, the output is simply the error messages, if any. No object file or ALI file is generated by a syntax-only compilation. Also, no units other than the one specified are accessed. For example, if a unit `X` `with`'s a unit `Y`, compiling unit `X` in syntax check only mode does not access the source file containing unit `Y`.

  Normally, GNAT allows only a single unit in a source file. However, this restriction does not apply in syntax-check-only mode, and it is possible to check a file containing multiple compilation units concatenated together. This is primarily used by the `gnatchop` utility (see section 8. Renaming Files with `gnatchop`).

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.8 Using `gcc` for Semantic Checking

``-gnatc'`

  The `c` stands for "check". Causes the compiler to operate in semantic check mode, with full checking for all illegalities specified in the Ada Reference Manual, but without generation of any object code (no object file is generated).

  Because dependent files must be accessed, you must follow the GNAT semantic restrictions on file structuring to operate in this mode:

  - The needed source files must be accessible (see section 3.3 Search Paths and the Run-Time Library (RTL)).

  - Each file must contain only one compilation unit.

  - The file name and unit name must match (see section 2.3 File Naming Rules).

  The output consists of error messages as appropriate. No object file is generated. An ``ALI'` file is generated for use in the context of cross-reference tools, but this file is marked as not being suitable for binding (since no object file is generated). The checking corresponds exactly to the notion of legality in the Ada Reference Manual.

  Any unit can be compiled in semantics-checking-only mode, including units that would not normally be compiled (subunits, and specifications where a separate body is present).

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.9 Compiling Different Versions of Ada

The switches described in this section allow you to explicitly specify the version of the Ada language that your programs are written in. The default mode is Ada 2012, but you can also specify Ada 95, Ada 2005 mode, or indicate Ada 83 compatibility mode.

``-gnat83 (Ada 83 Compatibility Mode)'`

  Although GNAT is primarily an Ada 95 / Ada 2005 compiler, this switch specifies that the program is to be compiled in Ada 83 mode. With ``-gnat83'`, GNAT rejects most post-Ada 83 extensions and applies Ada 83 semantics where this can be done easily. It is not possible to guarantee this switch does a perfect job; 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, existing 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 / Ada 2005 reserved words, and the use of packages with optional bodies), it is not necessary to specify the ``-gnat83'` switch when compiling Ada 83 programs, because, with rare exceptions, Ada 95 and Ada 2005 are upwardly compatible with Ada 83. Thus a correct Ada 83 program is usually also a correct program in these later versions of the language standard. For further information, please refer to G. Compatibility and Porting Guide.

``-gnat95 (Ada 95 mode)'`

  This switch directs the compiler to implement the Ada 95 version of the language. Since Ada 95 is almost completely upwards compatible with Ada 83, Ada 83 programs may generally be compiled using this switch (see the description of the ``-gnat83'` switch for further information about Ada 83 mode). If an Ada 2005 program is compiled in Ada 95 mode, uses of the new Ada 2005 features will cause error messages or warnings.

  This switch also can be used to cancel the effect of a previous ``-gnat83'`, ``-gnat05/2005'`, or ``-gnat12/2012'` switch earlier in the command line.

``-gnat05 or -gnat2005 (Ada 2005 mode)'`

  This switch directs the compiler to implement the Ada 2005 version of the language, as documented in the official Ada standards document. Since Ada 2005 is almost completely upwards compatible with Ada 95 (and thus also with Ada 83), Ada 83 and Ada 95 programs may generally be compiled using this switch (see the description of the ``-gnat83'` and ``-gnat95'` switches for further information).

``-gnat12 or -gnat2012 (Ada 2012 mode)'`

  This switch directs the compiler to implement the Ada 2012 version of the language (also the default). Since Ada 2012 is almost completely upwards compatible with Ada 2005 (and thus also with Ada 83, and Ada 95), Ada 83 and Ada 95 programs may generally be compiled using this switch (see the description of the ``-gnat83'`, ``-gnat95'`, and ``-gnat05/2005'` switches for further information).

``-gnatX (Enable GNAT Extensions)'`

  This switch directs the compiler to implement the latest version of the language (currently Ada 2012) and also to enable certain GNAT implementation extensions that are not part of any Ada standard. For a full list of these extensions, see the GNAT reference manual.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.10 Character Set Control

``-gnatic'`

  Normally GNAT recognizes the Latin-1 character set in source program identifiers, as described in the Ada Reference Manual. This switch causes GNAT to recognize alternate character sets in identifiers. c is a single character indicating the character set, as follows:

  `1`
    ISO 8859-1 (Latin-1) identifiers

  `2`
    ISO 8859-2 (Latin-2) letters allowed in identifiers

  `3`
    ISO 8859-3 (Latin-3) letters allowed in identifiers

  `4`
    ISO 8859-4 (Latin-4) letters allowed in identifiers

  `5`
    ISO 8859-5 (Cyrillic) letters allowed in identifiers

  `9`
    ISO 8859-15 (Latin-9) letters allowed in identifiers

  `p`
    IBM PC letters (code page 437) allowed in identifiers

  `8`
    IBM PC letters (code page 850) allowed in identifiers

  `f`
    Full upper-half codes allowed in identifiers

  `n`
    No upper-half codes allowed in identifiers

  `w`
    Wide-character codes (that is, codes greater than 255) allowed in identifiers

  See section 2.2 Foreign Language Representation, for full details on the implementation of these character sets.

``-gnatWe'`
  Specify the method of encoding for wide characters. e is one of the following:

  `h`
    Hex encoding (brackets coding also recognized)

  `u`
    Upper half encoding (brackets encoding also recognized)

  `s`
    Shift/JIS encoding (brackets encoding also recognized)

  `e`
    EUC encoding (brackets encoding also recognized)

  `8`
    UTF-8 encoding (brackets encoding also recognized)

  `b`
    Brackets encoding only (default value)
  For full details on these encoding methods see 2.2.3 Wide_Character Encodings. Note that brackets coding is always accepted, even if one of the other options is specified, so for example ``-gnatW8'` specifies that both brackets and UTF-8 encodings will be recognized. The units that are with'ed directly or indirectly will be scanned using the specified representation scheme, and so if one of the non-brackets scheme is used, it must be used consistently throughout the program. However, since brackets encoding is always recognized, it may be conveniently used in standard libraries, allowing these libraries to be used with any of the available coding schemes.

  Note that brackets encoding only applies to program text. Within comments, brackets are considered to be normal graphic characters, and bracket sequences are never recognized as wide characters.

  If no ``-gnatW?'` parameter is present, then the default representation is normally Brackets encoding only. However, if the first three characters of the file are 16#EF# 16#BB# 16#BF# (the standard byte order mark or BOM for UTF-8), then these three characters are skipped and the default representation for the file is set to UTF-8.

  Note that the wide character representation that is specified (explicitly or by default) for the main program also acts as the default encoding used for Wide_Text_IO files if not specifically overridden by a WCEM form parameter.

When no ``-gnatW?'` is specified, then characters (other than wide characters represented using brackets notation) are treated as 8-bit Latin-1 codes. The codes recognized are the Latin-1 graphic characters, and ASCII format effectors (CR, LF, HT, VT). Other lower half control characters in the range 16#00#..16#1F# are not accepted in program text or in comments. Upper half control characters (16#80#..16#9F#) are rejected in program text, but allowed and ignored in comments. Note in particular that the Next Line (NEL) character whose encoding is 16#85# is not recognized as an end of line in this default mode. If your source program contains instances of the NEL character used as a line terminator, you must use UTF-8 encoding for the whole source program. In default mode, all lines must be ended by a standard end of line sequence (CR, CR/LF, or LF).

Note that the convention of simply accepting all upper half characters in comments means that programs that use standard ASCII for program text, but UTF-8 encoding for comments are accepted in default mode, providing that the comments are ended by an appropriate (CR, or CR/LF, or LF) line terminator. This is a common mode for many programs with foreign language comments.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.11 File Naming Control

``-gnatkn'`
  Activates file name "krunching". n, a decimal integer in the range 1-999, indicates the maximum allowable length of a file name (not including the ``.ads'` or ``.adb'` extension). The default is not to enable file name krunching.

  For the source file naming rules, See section 2.3 File Naming Rules.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.12 Subprogram Inlining Control

``-gnatn[12]'`
  The `n` here is intended to suggest the first syllable of the word "inline". GNAT recognizes and processes `Inline` pragmas. However, for the inlining to actually occur, optimization must be enabled and, in order to enable inlining of subprograms specified by pragma `Inline`, you must also specify this switch. In the absence of this switch, GNAT does not attempt inlining and does not need to access the bodies of subprograms for which `pragma Inline` is specified if they are not in the current unit.

  You can optionally specify the inlining level: 1 for moderate inlining across modules, which is a good compromise between compilation times and performances at run time, or 2 for full inlining across modules, which may bring about longer compilation times. If no inlining level is specified, the compiler will pick it based on the optimization level: 1 for ``-O1'`, ``-O2'` or ``-Os'` and 2 for ``-O3'`.

  If you specify this switch the compiler will access these bodies, creating an extra source dependency for the resulting object file, and where possible, the call will be inlined. For further details on when inlining is possible see 7.1.5 Inlining of Subprograms.

``-gnatN'`
  This switch activates front-end inlining which also generates additional dependencies.

  When using a gcc-based back end (in practice this means using any version of GNAT other than the JGNAT, .NET or GNAAMP versions), then the use of ``-gnatN'` is deprecated, and the use of ``-gnatn'` is preferred. Historically front end inlining was more extensive than the gcc back end inlining, but that is no longer the case.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.13 Auxiliary Output Control

``-gnatt'`
  Causes GNAT to write the internal tree for a unit to a file (with the extension ``.adt'`. This not normally required, but is used by separate analysis tools. Typically these tools do the necessary compilations automatically, so you should not have to specify this switch in normal operation. Note that the combination of switches ``-gnatct'` generates a tree in the form required by ASIS applications.

``-gnatu'`
  Print a list of units required by this compilation on ``stdout'`. The listing includes all units on which the unit being compiled depends either directly or indirectly.

``-pass-exit-codes'`
  If this switch is not used, the exit code returned by `gcc` when compiling multiple files indicates whether all source files have been successfully used to generate object files or not.

  When ``-pass-exit-codes'` is used, `gcc` exits with an extended exit status and allows an integrated development environment to better react to a compilation failure. Those exit status are:

  5
    There was an error in at least one source file.
  3
    At least one source file did not generate an object file.
  2
    The compiler died unexpectedly (internal error for example).
  0
    An object file has been generated for every source file.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.14 Debugging Control

``-gnatdx'`
  Activate internal debugging switches. x is a letter or digit, or string of letters or digits, which specifies the type of debugging outputs desired. Normally these are used only for internal development or system debugging purposes. You can find full documentation for these switches in the body of the `Debug` unit in the compiler source file ``debug.adb'`.

``-gnatG[=nn]'`
  This switch causes the compiler to generate auxiliary output containing a pseudo-source listing of the generated expanded code. Like most Ada compilers, GNAT works by first transforming the high level Ada code into lower level constructs. For example, tasking operations are transformed into calls to the tasking run-time routines. A unique capability of GNAT is to list this expanded code in a form very close to normal Ada source. This is very useful in understanding the implications of various Ada usage on the efficiency of the generated code. There are many cases in Ada (e.g. the use of controlled types), where simple Ada statements can generate a lot of run-time code. By using ``-gnatG'` you can identify these cases, and consider whether it may be desirable to modify the coding approach to improve efficiency.

  The optional parameter `nn` if present after -gnatG specifies an alternative maximum line length that overrides the normal default of 72. This value is in the range 40-999999, values less than 40 being silently reset to 40. The equal sign is optional.

  The format of the output is very similar to standard Ada source, and is easily understood by an Ada programmer. The following special syntactic additions correspond to low level features used in the generated code that do not have any exact analogies in pure Ada source form. The following is a partial list of these special constructions. See the spec of package `Sprint` in file ``sprint.ads'` for a full list.

  If the switch ``-gnatL'` is used in conjunction with ``-gnatG'`, then the original source lines are interspersed in the expanded source (as comment lines with the original line number).

  `new xxx [storage_pool = yyy]`
    Shows the storage pool being used for an allocator.

  `at end procedure-name;`
    Shows the finalization (cleanup) procedure for a scope.

  `(if expr then expr else expr)`
    Conditional expression equivalent to the `x?y:z` construction in C.

  `target^(source)`
    A conversion with floating-point truncation instead of rounding.

  `target?(source)`
    A conversion that bypasses normal Ada semantic checking. In particular enumeration types and fixed-point types are treated simply as integers.

  `target?^(source)`
    Combines the above two cases.

  `x #/ y`
  `x #mod y`
  `x #* y`
  `x #rem y`
    A division or multiplication of fixed-point values which are treated as integers without any kind of scaling.

  `free expr [storage_pool = xxx]`
    Shows the storage pool associated with a `free` statement.

  `[subtype or type declaration]`
    Used to list an equivalent declaration for an internally generated type that is referenced elsewhere in the listing.

  `freeze type-name [actions]`
    Shows the point at which type-name is frozen, with possible associated actions to be performed at the freeze point.

  `reference itype`
    Reference (and hence definition) to internal type itype.

  `function-name! (arg, arg, arg)`
    Intrinsic function call.

  `label-name : label`
    Declaration of label labelname.

  `#$ subprogram-name`
    An implicit call to a run-time support routine (to meet the requirement of H.3.1(9) in a convenient manner).

  `expr && expr && expr ... && expr`
    A multiple concatenation (same effect as expr & expr & expr, but handled more efficiently).

  `[constraint_error]`
    Raise the `Constraint_Error` exception.

  `expression'reference`
    A pointer to the result of evaluating expression.

  `target-type!(source-expression)`
    An unchecked conversion of source-expression to target-type.

  `[numerator/denominator]`
    Used to represent internal real literals (that) have no exact representation in base 2-16 (for example, the result of compile time evaluation of the expression 1.0/27.0).

``-gnatD[=nn]'`
  When used in conjunction with ``-gnatG'`, this switch causes the expanded source, as described above for ``-gnatG'` to be written to files with names ``xxx.dg'`, where ``xxx'` is the normal file name, instead of to the standard output file. For example, if the source file name is ``hello.adb'`, then a file ``hello.adb.dg'` will be written. The debugging information generated by the `gcc` ``-g'` switch will refer to the generated ``xxx.dg'` file. This allows you to do source level debugging using the generated code which is sometimes useful for complex code, for example to find out exactly which part of a complex construction raised an exception. This switch also suppress generation of cross-reference information (see ``-gnatx'`) since otherwise the cross-reference information would refer to the ``.dg'` file, which would cause confusion since this is not the original source file.

  Note that ``-gnatD'` actually implies ``-gnatG'` automatically, so it is not necessary to give both options. In other words ``-gnatD'` is equivalent to ``-gnatDG'`).

  If the switch ``-gnatL'` is used in conjunction with ``-gnatDG'`, then the original source lines are interspersed in the expanded source (as comment lines with the original line number).

  The optional parameter `nn` if present after -gnatD specifies an alternative maximum line length that overrides the normal default of 72. This value is in the range 40-999999, values less than 40 being silently reset to 40. The equal sign is optional.

``-gnatr'`
  This switch causes pragma Restrictions to be treated as Restriction_Warnings so that violation of restrictions causes warnings rather than illegalities. This is useful during the development process when new restrictions are added or investigated. The switch also causes pragma Profile to be treated as Profile_Warnings, and pragma Restricted_Run_Time and pragma Ravenscar set restriction warnings rather than restrictions.

``-gnatR[0|1|2|3[s]]'`
  This switch controls output from the compiler of a listing showing representation information for declared types and objects. For ``-gnatR0'`, no information is output (equivalent to omitting the ``-gnatR'` switch). For ``-gnatR1'` (which is the default, so ``-gnatR'` with no parameter has the same effect), size and alignment information is listed for declared array and record types. For ``-gnatR2'`, size and alignment information is listed for all declared types and objects. The `Linker_Section` is also listed for any entity for which the `Linker_Section` is set explicitly or implicitly (the latter case occurs for objects of a type for which a `Linker_Section` is set).

  Finally ``-gnatR3'` includes symbolic expressions for values that are computed at run time for variant records. These symbolic expressions have a mostly obvious format with #n being used to represent the value of the n'th discriminant. See source files ``repinfo.ads/adb'` in the `GNAT` sources for full details on the format of ``-gnatR3'` output. If the switch is followed by an s (e.g. ``-gnatR2s'`), then the output is to a file with the name ``file.rep'` where file is the name of the corresponding source file.

``-gnatRm[s]'`
  This form of the switch controls output of subprogram conventions and parameter passing mechanisms for all subprograms. A following `s` means output to a file as described above.

  Note that it is possible for record components to have zero size. In this case, the component clause uses an obvious extension of permitted Ada syntax, for example `at 0 range 0 .. -1`.

  Representation information requires that code be generated (since it is the code generator that lays out complex data structures). If an attempt is made to output representation information when no code is generated, for example when a subunit is compiled on its own, then no information can be generated and the compiler outputs a message to this effect.

``-gnatS'`
  The use of the switch ``-gnatS'` for an Ada compilation will cause the compiler to output a representation of package Standard in a form very close to standard Ada. It is not quite possible to do this entirely in standard Ada (since new numeric base types cannot be created in standard Ada), but the output is easily readable to any Ada programmer, and is useful to determine the characteristics of target dependent types in package Standard.

``-gnatx'`
  Normally the compiler generates full cross-referencing information in the ``ALI'` file. This information is used by a number of tools, including `gnatfind` and `gnatxref`. The ``-gnatx'` switch suppresses this information. This saves some space and may slightly speed up compilation, but means that these tools cannot be used.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.15 Exception Handling Control

GNAT uses two methods for handling exceptions at run-time. The `setjmp/longjmp` method saves the context when entering a frame with an exception handler. Then when an exception is raised, the context can be restored immediately, without the need for tracing stack frames. This method provides very fast exception propagation, but introduces significant overhead for the use of exception handlers, even if no exception is raised.

The other approach is called "zero cost" exception handling. With this method, the compiler builds static tables to describe the exception ranges. No dynamic code is required when entering a frame containing an exception handler. When an exception is raised, the tables are used to control a back trace of the subprogram invocation stack to locate the required exception handler. This method has considerably poorer performance for the propagation of exceptions, but there is no overhead for exception handlers if no exception is raised. Note that in this mode and in the context of mixed Ada and C/C++ programming, to propagate an exception through a C/C++ code, the C/C++ code must be compiled with the ``-funwind-tables'` GCC's option.

The following switches may be used to control which of the two exception handling methods is used.

``--RTS=sjlj'`
  This switch causes the setjmp/longjmp run-time (when available) to be used for exception handling. If the default mechanism for the target is zero cost exceptions, then this switch can be used to modify this default, and must be used for all units in the partition. This option is rarely used. One case in which it may be advantageous is if you have an application where exception raising is common and the overall performance of the application is improved by favoring exception propagation.

``--RTS=zcx'`
  This switch causes the zero cost approach to be used for exception handling. If this is the default mechanism for the target (see below), then this switch is unneeded. If the default mechanism for the target is setjmp/longjmp exceptions, then this switch can be used to modify this default, and must be used for all units in the partition. This option can only be used if the zero cost approach is available for the target in use, otherwise it will generate an error.

The same option ``--RTS'` must be used both for `gcc` and `gnatbind`. Passing this option to `gnatmake` (see section 6.2 Switches for `gnatmake`) will ensure the required consistency through the compilation and binding steps.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.16 Units to Sources Mapping Files

``-gnatem=path'`
  A mapping file is a way to communicate to the compiler two mappings: from unit names to file names (without any directory information) and from file names to path names (with full directory information). These mappings are used by the compiler to short-circuit the path search.

  The use of mapping files is not required for correct operation of the compiler, but mapping files can improve efficiency, particularly when sources are read over a slow network connection. In normal operation, you need not be concerned with the format or use of mapping files, and the ``-gnatem'` switch is not a switch that you would use explicitly. It is intended primarily for use by automatic tools such as `gnatmake` running under the project file facility. The description here of the format of mapping files is provided for completeness and for possible use by other tools.

  A mapping file is a sequence of sets of three lines. In each set, the first line is the unit name, in lower case, with `%s` appended for specs and `%b` appended for bodies; the second line is the file name; and the third line is the path name.

  Example:

         main%b
         main.2.ada
         /gnat/project1/sources/main.2.ada

  When the switch ``-gnatem'` is specified, the compiler will create in memory the two mappings from the specified file. If there is any problem (nonexistent file, truncated file or duplicate entries), no mapping will be created.

  Several ``-gnatem'` switches may be specified; however, only the last one on the command line will be taken into account.

  When using a project file, `gnatmake` creates a temporary mapping file and communicates it to the compiler using this switch.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.17 Integrated Preprocessing

GNAT sources may be preprocessed immediately before compilation. In this case, the actual text of the source is not the text of the source file, but is derived from it through a process called preprocessing. Integrated preprocessing is specified through switches ``-gnatep'` and/or ``-gnateD'`. ``-gnatep'` indicates, through a text file, the preprocessing data to be used. ``-gnateD'` specifies or modifies the values of preprocessing symbol. Note that integrated preprocessing applies only to Ada source files, it is not available for configuration pragma files.

Note that when integrated preprocessing is used, the output from the preprocessor is not written to any external file. Instead it is passed internally to the compiler. If you need to preserve the result of preprocessing in a file, then you should use `gnatprep` to perform the desired preprocessing in stand-alone mode.

It is recommended that `gnatmake` switch -s should be used when Integrated Preprocessing is used. The reason is that preprocessing with another Preprocessing Data file without changing the sources will not trigger recompilation without this switch.

Note that `gnatmake` switch -m will almost always trigger recompilation for sources that are preprocessed, because `gnatmake` cannot compute the checksum of the source after preprocessing.

The actual preprocessing function is described in details in section 18. Preprocessing with `gnatprep`. This section only describes how integrated preprocessing is triggered and parameterized.

`-gnatep=file`
  This switch indicates to the compiler the file name (without directory information) of the preprocessor data file to use. The preprocessor data file should be found in the source directories. Note that when the compiler is called by a builder such as (`gnatmake` with a project file, if the object directory is not also a source directory, the builder needs to be called with ``-x'`.

  A preprocessing data file is a text file with significant lines indicating how should be preprocessed either a specific source or all sources not mentioned in other lines. A significant line is a nonempty, non-comment line. Comments are similar to Ada comments.

  Each significant line starts with either a literal string or the character '*'. A literal string is the file name (without directory information) of the source to preprocess. A character '*' indicates the preprocessing for all the sources that are not specified explicitly on other lines (order of the lines is not significant). It is an error to have two lines with the same file name or two lines starting with the character '*'.

  After the file name or the character '*', another optional literal string indicating the file name of the definition file to be used for preprocessing (see section 18.4 Form of Definitions File). The definition files are found by the compiler in one of the source directories. In some cases, when compiling a source in a directory other than the current directory, if the definition file is in the current directory, it may be necessary to add the current directory as a source directory through switch -I., otherwise the compiler would not find the definition file.

  Then, optionally, switches similar to those of `gnatprep` may be found. Those switches are:

  `-b`
    Causes both preprocessor lines and the lines deleted by preprocessing to be replaced by blank lines, preserving the line number. This switch is always implied; however, if specified after ``-c'` it cancels the effect of ``-c'`.

  `-c`
    Causes both preprocessor lines and the lines deleted by preprocessing to be retained as comments marked with the special string "`--!` ".

  `-Dsymbol=value`
    Define or redefine a symbol, associated with value. A symbol is an Ada identifier, or an Ada reserved word, with the exception of `if`, `else`, `elsif`, `end`, `and`, `or` and `then`. `value` is either a literal string, an Ada identifier or any Ada reserved word. A symbol declared with this switch replaces a symbol with the same name defined in a definition file.

  `-s`
    Causes a sorted list of symbol names and values to be listed on the standard output file.

  `-u`
    Causes undefined symbols to be treated as having the value `FALSE` in the context of a preprocessor test. In the absence of this option, an undefined symbol in a `#if` or `#elsif` test will be treated as an error.

  Examples of valid lines in a preprocessor data file:

        "toto.adb"  "prep.def" -u
        --  preprocess "toto.adb", using definition file "prep.def",
        --  undefined symbol are False.

        * -c -DVERSION=V101
        --  preprocess all other sources without a definition file;
        --  suppressed lined are commented; symbol VERSION has the value V101.

        "titi.adb" "prep2.def" -s
        --  preprocess "titi.adb", using definition file "prep2.def";
        --  list all symbols with their values.

`-gnateDsymbol[=value]`
  Define or redefine a preprocessing symbol, associated with value. If no value is given on the command line, then the value of the symbol is `True`. A symbol is an identifier, following normal Ada (case-insensitive) rules for its syntax, and value is either an arbitrary string between double quotes or any sequence (including an empty sequence) of characters from the set (letters, digits, period, underline). Ada reserved words may be used as symbols, with the exceptions of `if`, `else`, `elsif`, `end`, `and`, `or` and `then`.

  Examples:

         -gnateDToto=Titi
         -gnateDFoo
         -gnateDFoo=\"Foo-Bar\"

  A symbol declared with this switch on the command line replaces a symbol with the same name either in a definition file or specified with a switch -D in the preprocessor data file.

  This switch is similar to switch ``-D'` of `gnatprep`.

`-gnateG`
  When integrated preprocessing is performed and the preprocessor modifies the source text, write the result of this preprocessing into a file <source>.prep.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.2.18 Code Generation Control

The GCC technology provides a wide range of target dependent ``-m'` switches for controlling details of code generation with respect to different versions of architectures. This includes variations in instruction sets (e.g. different members of the power pc family), and different requirements for optimal arrangement of instructions (e.g. different members of the x86 family). The list of available ``-m'` switches may be found in the GCC documentation.

Use of these ``-m'` switches may in some cases result in improved code performance.

The GNAT GPL technology is tested and qualified without any ``-m'` switches, so generally the most reliable approach is to avoid the use of these switches. However, we generally expect most of these switches to work successfully with GNAT GPL, and many customers have reported successful use of these options.

Our general advice is to avoid the use of ``-m'` switches unless special needs lead to requirements in this area. In particular, there is no point in using ``-m'` switches to improve performance unless you actually see a performance improvement.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.3 Search Paths and the Run-Time Library (RTL)

With the GNAT source-based library system, the compiler must be able to find source files for units that are needed by the unit being compiled. Search paths are used to guide this process.

The compiler compiles one source file whose name must be given explicitly on the command line. In other words, no searching is done for this file. To find all other source files that are needed (the most common being the specs of units), the compiler examines the following directories, in the following order:

1. The directory containing the source file of the main unit being compiled (the file name on the command line).

2. Each directory named by an ``-I'` switch given on the `gcc` command line, in the order given.

3. Each of the directories listed in the text file whose name is given by the `ADA_PRJ_INCLUDE_FILE` environment variable.

   `ADA_PRJ_INCLUDE_FILE` is normally set by gnatmake or by the gnat driver when project files are used. It should not normally be set by other means.

4. Each of the directories listed in the value of the `ADA_INCLUDE_PATH` environment variable. Construct this value exactly as the `PATH` environment variable: a list of directory names separated by colons (semicolons when working with the NT version).

5. The content of the ``ada_source_path'` file which is part of the GNAT installation tree and is used to store standard libraries such as the GNAT Run Time Library (RTL) source files. 21.2.2 Installing a library

Specifying the switch ``-I-'` inhibits the use of the directory containing the source file named in the command line. You can still have this directory on your search path, but in this case it must be explicitly requested with a ``-I'` switch.

Specifying the switch ``-nostdinc'` inhibits the search of the default location for the GNAT Run Time Library (RTL) source files.

The compiler outputs its object files and ALI files in the current working directory. Caution: The object file can be redirected with the ``-o'` switch; however, `gcc` and `gnat1` have not been coordinated on this so the ``ALI'` file will not go to the right place. Therefore, you should avoid using the ``-o'` switch.

The packages `Ada`, `System`, and `Interfaces` and their children make up the GNAT RTL, together with the simple `System.IO` package used in the `"Hello World"` example. The sources for these units are needed by the compiler and are kept together in one directory. Not all of the bodies are needed, but all of the sources are kept together anyway. In a normal installation, you need not specify these directory names when compiling or binding. Either the environment variables or the built-in defaults cause these files to be found.

In addition to the language-defined hierarchies (`System`, `Ada` and `Interfaces`), the GNAT distribution provides a fourth hierarchy, consisting of child units of `GNAT`. This is a collection of generally useful types, subprograms, etc. See section `About This Guid' in GNAT Reference Manual, for further details.

Besides simplifying access to the RTL, a major use of search paths is in compiling sources from multiple directories. This can make development environments much more flexible.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.4 Order of Compilation Issues

If, in our earlier example, there was a spec for the `hello` procedure, it would be contained in the file ``hello.ads'`; yet this file would not have to be explicitly compiled. This is the result of the model we chose to implement library management. Some of the consequences of this model are as follows:

- There is no point in compiling specs (except for package specs with no bodies) because these are compiled as needed by clients. If you attempt a useless compilation, you will receive an error message. It is also useless to compile subunits because they are compiled as needed by the parent.

- There are no order of compilation requirements: performing a compilation never obsoletes anything. The only way you can obsolete something and require recompilations is to modify one of the source files on which it depends.

- There is no library as such, apart from the ALI files (see section 2.8 The Ada Library Information Files, for information on the format of these files). For now we find it convenient to create separate ALI files, but eventually the information therein may be incorporated into the object file directly.

- When you compile a unit, the source files for the specs of all units that it `with`'s, all its subunits, and the bodies of any generics it instantiates must be available (reachable by the search-paths mechanism described above), or you will receive a fatal error message.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.5 Examples

The following are some typical Ada compilation command line examples:

`$ gcc -c xyz.adb`
  Compile body in file ``xyz.adb'` with all default options.

`$ gcc -c -O2 -gnata xyz-def.adb`

  Compile the child unit package in file ``xyz-def.adb'` with extensive optimizations, and pragma `Assert`/`Debug` statements enabled.

`$ gcc -c -gnatc abc-def.adb`
  Compile the subunit in file ``abc-def.adb'` in semantic-checking-only mode.

[ << ] | [ >> ] |  |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated by GNAT Mailserver on April, 17 2014 using texi2html