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

3. Compiling Using gnatgcc

This chapter discusses how to compile Ada programs using the gnatgcc 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 gnatgcc  
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 gnatgcc command. You must compile the following files:

You need not compile the following files

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):

 
   No code generated for file fff (package spec)
   No code generated for file fff (subunit)

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

 
   $ gnatgcc -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 gnatgcc 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.

gnatgcc 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 gnatgcc 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 gnatgcc command. This causes gnatgcc to call the appropriate compiler for each file. For example, the following command lists three separate files to be compiled:

 
   $ gnatgcc -c x.adb y.adb z.c

calls gnat1 (the Ada compiler) twice to compile `x.adb' and `y.adb', and cc1 (the C compiler) once to compile `z.c'. The compiler generates three object files `x.o', `y.o' and `z.o' and the two ALI files `x.ali' and `y.ali' from the Ada compilations. Any switches apply to all the files listed, except for -gnatx switches, which apply only to Ada compilations.


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

3.2 Switches for gnatgcc

The gnatgcc command accepts numerous switches to control the compilation process. These switches are fully described in this section.

3.2.1 Output and Error Message Control  
3.2.2 Debugging and Assertion Control  
3.2.4 Run-time Checks  
3.2.3 Style Checking  
3.2.5 Using gnatgcc for Syntax Checking  
3.2.6 Using gnatgcc for Semantic Checking  
3.2.7 Compiling Ada 83 Programs  
3.2.8 Reference Manual Style Checking  
3.2.9 Character Set Control  
3.2.10 File Naming Control  
3.2.11 Subprogram Inlining Control  
3.2.12 Auxiliary Output Control  
3.2.13 Debugging 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 the gnatgcc manual page for further details. You would normally use the -b or -V switch instead.

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

Note that you may not use gnatgcc without a -c switch to compile and link in one step. This is because the binder must be run, and currently gnatgcc cannot be used to run the GNAT binder.

-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.

-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-
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)).

-o file
This switch is used in gnatgcc 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.

-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.

n = 2
Extensive optimization

n = 3
Extensive optimization with automatic inlining. This applies only to inlining within a unit. For details on control of inter-unit inlining see See section 3.2.11 Subprogram Inlining Control.

-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.

-v
Show commands generated by the gnatgcc 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 gnatgcc version, not the GNAT version.

-Wuninitialized
Generate warnings for uninitialized variables. You must also specify the -O switch (in other words, This switch works only if optimization is turned on).

-gnata
Assertions enabled. Pragma Assert and pragma Debug to be activated.

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

-gnatc
Check syntax and semantics only (no code generation attempted).

-gnatD
Output expanded source files for source level debugging.

-gnate
Force error message generation (for use when compiler crashes).

-gnatE
Full dynamic elaboration checks.

-gnatf
Full errors. Multiple errors per line, all undefined references.

-gnatg
GNAT style checks enabled.

-gnatG
List generated expanded code in source form.

-gnatic
Identifier character set (c=1/2/3/4/8/p/f/n/w).

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

-gnatkn
Limit file names to n (1-999) characters (k = krunch).

-gnatl
Output full source listing with embedded error messages.

-gnatmn
Limit number of detected errors to n (1-999).

-gnatn
Activate inlining across unit boundaries for subprograms for which pragma inline is specified.

-gnatN
Activate inlining across unit boundaries for all subprograms (not just those for which pragma inline is specified. This is equivalent to using -gnatn and adding a pragma inline for every subprogram in the program.

-fno-inline
Suppresses all inlining, even if other optimization or inlining switches are set.

-gnato
Enable other checks, not normally enabled by default, including numeric overflow checking, and access before elaboration checks.

-gnatp
Suppress all checks.

-gnatq
Don't quit; try semantics, even if parse errors.

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

-gnatR
Output representation information for declared array and record types.

-gnats
Syntax check only.

-gnatt
Tree output file to be generated.

-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.

-gnatwm
Warning mode (m=s,e,l for suppress, treat as error, elaboration warnings).

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

-gnatx
Suppress generation of cross-reference information.

-gnatwm
Warning mode
-gnaty
Enable built-in style checks. See separate section describing this feature.

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

-gnat83
Enforce Ada 83 restrictions.

-gnat95
Standard Ada 95 mode

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

 
   -gnatcfi3

is equivalent to specifying the following sequence of switches:

 
   -gnatc -gnatf -gnati3


[ < ] [ > ]   [ << ] [ 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 stdout (the standard output 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. emacs 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 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. The output might look as follows:

 
    1. procedure E is
    2.    V : Integer;
    3.    funcion X (Q : Integer)
          |
       >>> Incorrect spelling of keyword "function"
    4.     return Integer;
                         |
       >>> ";" should be "is"
    5.    begin
    6.       return Q + Q;
    7.    end;
    8. begin
    9.    V := X + X;
   10.end E;

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.

-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 stdout as well as the verbose format message or full listing.

-gnatmn
The m stands for maximum. n is a decimal integer in the range of 1 to 999 and limits the number of error 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 errors reached
   compilation abandoned

-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

-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.

-gnate
Normally, the compiler saves up error messages and generates them at the end of compilation in proper sequence. This switch (the `e' stands for error) causes error messages to be generated as soon as they are detected. The use of -gnate may cause error messages to be generated out of sequence and also disconnects a number of useful error message processing circuits. This switch should be used only in error situations where the compiler terminates with no output at all, or goes into an infinite loop. In such cases, the -gnate switch may be used to see if any error situations were detected before the compiler crash (see section 20.9 GNAT Abnormal Termination).

In addition to error messages, which correspond to illegalities as defined in the Ada 95 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:

Four switches are available to control the handling of warning messages:

-gnatwe (treat warnings as errors)
This switch causes warning 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.

-gnatws (suppress warnings)
This switch completely suppresses the output of all warning messages.

-gnatwl (warn on elaboration order errors)
This switch causes the generation of additional warning messages relating to elaboration issues. See the separate chapter on elaboration order handling for full details of the use of this switch.

-gnatwu (warn on unused entities)
This switch causes warning messages to be generated for entities that are defined 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 the 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.

-gnatR
Use of the switch -gnatR causes the compiler to output a listing showing representation information for declared array and record types, including record representation clauses.

-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.2 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_Error 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.3 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 error message is given, preceded by the character sequence "(style)", and the program is considered illegal. The string x is a sequence of letters or digits indicating the particular style checks to be performed. The following checks are defined:

1-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. 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.

a (check attribute casing)
If the letter a appears in the string after -gnaty then 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.

b (blanks not allowed at statement end)
If the letter b appears in the string after -gnaty then 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.

c (check comments)
If the letter c appears in the string after -gnaty then comments must meet the following set of rules:

e (check end labels)
If the letter e appears in the string after -gnaty then optional labels on end statements ending subprograms are required to be present.

f (no form feeds or vertical tabs)
If the letter f appears in the string after -gnaty then neither form feeds nor vertical tab characters are not permitted in the source text.

h (no horizontal tabs)
If the letter h appears in the string after -gnaty then 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)
If the letter i appears in the string after -gnaty, then 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 with at least one non-blank line in between containing all or part of the condition to be tested.

k (check keyword casing)
If the letter k appears in the string after -gnaty then 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)
If the letter l appears in the string after -gnaty then 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. For example, either of the following two layouts is acceptable:

 
   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;

m (check maximum line length)
If the letter m appears in the string after -gnaty then 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.

Mnnn (set maximum line length)
If the sequence Mnnn, where nnn is a decimal number, appears in the string after -gnaty then the length of lines must not exceed the given value.

p (check pragma casing)
If the letter p appears in the string after -gnaty then 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.

r (check references)
If the letter r appears in the string after -gnaty then 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)
If the letter s appears in the string after -gnaty then 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.

t (check token spacing)
If the letter t appears in the string after -gnaty then the following token spacing rules are enforced:

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.

The switch -gnaty on its own (that is not followed by any letters or digits), is equivalent to gnaty3abcefhiklmprst, that is all checking options are enabled, with an indentation level of 3. This is the standard checking option that is used for the GNAT sources.


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

3.2.4 Run-time Checks

If you compile with the default options, GNAT will insert many run-time checks into the compiled code, including code that performs range checking against constraints, but not arithmetic overflow checking for integer operations (including division by zero) or checks for access before elaboration on subprogram calls. All other run-time checks, as required by the Ada 95 Reference Manual, are generated by default. The following gnatgcc switches refine this default behavior:

-gnatp
Suppress all run-time checks as though pragma Suppress (all_checks) had been present in the source. Use this switch to improve the performance of the code at the expense of safety in the presence of invalid data or program bugs.

-gnato
Enables overflow checking for integer operations. This causes GNAT to generate slower and larger executable programs by adding code to check for both overflow and division by zero (resulting in raising Constraint_Error as required by Ada semantics). Note that the -gnato switch does not affect the code generated for any floating-point operations; it applies only to integer operations. For floating-point, GNAT 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).

-gnatE
Enables dynamic checks for access-before-elaboration on subprogram calls and generic instantiations. For full details of the effect and use of this switch, See section 3. Compiling Using gnatgcc.

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.5 Using gnatgcc for Syntax Checking

-gnats

The s stands for syntax.

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

 
   $ gnatgcc -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.

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 7. Renaming Files Using gnatchop).


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

3.2.6 Using gnatgcc 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 95 Reference Manual, but without generation of any source code (no object or ALI file generated).

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

The output consists of error messages as appropriate. No object file or ALI file is generated. The checking corresponds exactly to the notion of legality in the Ada 95 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.7 Compiling Ada 83 Programs

-gnat83

Although GNAT is primarily an Ada 95 compiler, it accepts this switch to specify that an Ada 83 program is to be compiled in Ada83 mode. If you specify this switch, GNAT rejects most Ada 95 extensions and applies Ada 83 semantics where this can be done easily. It is not possible to guarantee this switch does a perfect job; for example, some subtle tests, such as are found in earlier ACVC tests (that have been removed from the ACVC suite for Ada 95), may not compile correctly. However, for most purposes, using this switch should help to ensure that programs that compile correctly under the -gnat83 switch can be ported easily to an Ada 83 compiler. This is the main use of the switch.

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

-gnat95
This switch specifies normal Ada 95 mode, and cancels the effect of any previously given -gnat83 switch.


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

3.2.8 Reference Manual Style Checking

-gnatr

Normally, GNAT permits any source layout consistent with the Ada 95 reference manual requirements. This switch (`r' is for "reference manual") enforces the layout conventions suggested by the examples and syntax rules of the Ada 95 Language Reference Manual. For example, an else must line up with an if and code in the then and else parts must be indented. The compiler treats violations of the layout rules as syntax errors if you specify this switch.

-gnatg
Enforces a set of style conventions that correspond to the style used in the GNAT source code. All compiler units are always compiled with the -gnatg switch specified.

You can find the full documentation for the style conventions imposed by -gnatg in the body of the package Style in the compiler sources (in the file `style.adb').

You should not normally use the -gnatg switch. However, you must use -gnatg for compiling any language-defined unit, or for adding children to any language-defined unit other than Standard.


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

3.2.9 Character Set Control

-gnatic

Normally GNAT recognizes the Latin-1 character set in source program identifiers, as described in the Ada 95 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
Latin-1 identifiers

2
Latin-2 letters allowed in identifiers

3
Latin-3 letters allowed in identifiers

4
Latin-4 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 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 the these encoding methods see See section 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. scheme. If no -gnatW? parameter is present, then the default representation is Brackets encoding only.

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.


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

3.2.10 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.11 Subprogram Inlining Control

-gnatn
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. To enable inlining across unit boundaries, this is, inlining a call in one unit of a subprogram declared in a with'ed unit, you must also specify this switch. In the absence of this switch, GNAT does not attempt inlining across units and does not need to access the bodies of subprograms for which pragma Inline is specified if they are not in the current unit.

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 See section 21.3 Inlining of Subprograms.

-gnatN
This switch enforces a more extreme form of inlining across unit boundaries. It causes the compiler to proceed as though the normal (pragma) inlining switch was set, and to assume that there is a pragma Inline for every subprogram referenced by the compiled unit.


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

3.2.12 Auxiliary Output Control

-gnatt
Cause GNAT to write the internal tree for a unit to a file (with the extension `.atb' for a body or `.ats' for a spec). This is not normally required, but is used by separate analysis tools. Typically these tools do the necessary compilations automatically, so you should never have to specify this switch in normal operation.

-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.


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

3.2.13 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
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 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:

-gnatD
This switch is used in conjunction with -gnatG to cause the expanded source, as described above to be written to files with names `xxx.dg', where `xxx' is the normal file name, 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 gnatgcc -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.

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.

freeze typename [actions]
Shows the point at which typename 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.

labelname : label
Declaration of label labelname.

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).


[ < ] [ > ]   [ << ] [ 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 gnatgcc command line, in the order given.

  3. 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.

  4. The default location for the GNAT Run Time Library (RTL) source files. This is determined at the time GNAT is built and installed on your system.

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, gnatgcc 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 routines. See the 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:


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

3.5 Examples

The following are some typical Ada compilation command line examples:

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

$ gnatgcc -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.

$ gnatgcc -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 Tom Bennet on August, 25 2000 using texi2html