Next: , Previous: Run-Time Checks, Up: Compiler Switches


4.3.8 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 (Renaming Files with gnatchop).