• Aucun résultat trouvé

Preprocessor (gspcpp) Description

Dans le document TMS34010 C Compiler (Page 23-27)

C Compiler Operation

3.1 Preprocessor (gspcpp) Description

The first step in compiling a TMS34010 C program is invoking the C pre-processor. The preprocessor handles macro definitions and substitutions,

#include files, line number directives, and conditional compilation. As Figure 3-2 shows, the preprocessor uses a C source file as input, and produces a

Figure 3-2. Input and Output Files for the C Preprocessor

3.1.1 Invoking the C Preprocessor

3-2

To invoke the preprocessor, enter:

gspcpp [input file [output file]] [options]

gspcpp is the command that invokes the preprocessor.

input file names a C source file that the preprocessor uses as input. If you don't supply an extension, the preprocessor assumes that the extension is

.c.

If you don't specify an input file, the pre-processor will prompt you for one.

output file names the modified source file that the preprocessor creates. If you don't supply a filename for the output file, the preprocessor uses the input filename with an extension of .cpp.

options affect the way the preprocessor processes your input file. An option is a single letter preceded by a hyphen; some options have additional fields which follow the option with no interven-ing spaces. Options are not case sensitive. Valid options

Compiler Operation - Preprocessor Description

-dname[=def] defines name as if it were #defined in a C source file (as in #def ine name def). You can use name in #if and #ifdef statements without explicitly defining it in the C source. The =def is optional; if you don't use it, name and file information.

-q is the "quiet" option; it suppresses the banner and status information.

Note that options can appear anywhere on the command line.

3.1.2 General Information

• This preprocessor is the same preprocessor that is described in Kerni-ghan and Ritchie; additional information can be found in that book. This preprocessor supports the same preprocessor directives that are de-scribed in Kernighan and Ritchie (Appendix B summarizes these direc-tives). All preprocessor directives begin with the character #, which must appear in column 1 of the source statement. Any number of blanks and tabs may appear between the # sign and the directive name.

• The C preprocessor maintains and recognizes five predefined macro names:

__ LINE _ _ represents the current line number (maintained as a dec-imal integer).

-gspc identifies the compiler as the TMS3401 0 C compiler; this symbol is defined as the constant 1.

You can use these names in the same manner as any other defined name.

For example,

printf ("%s %s", __ TIME __ , __ DATE __ ) ; would translate into a line such as:

printf(%s %s", "Jan 14 1988", "13:58:17"};

• The preprocessor produces self-explanatory error messages. The line number and the filename where the error occurred are printed along with a diagnostic message.

Compiler Operation - Preprocessor Description

3.1.3 Specifying Alternate Directories for Include Files

The #include preprocessor directive tells the preprocessor to read source statements from another file. The syntax for this directive is:

#include "filename" or #include <filename>

The filename names an include file that the preprocessor reads statements from; you can enclose the filename in double quotes or in angle brackets. The filename can be a complete pathname or a filename with no path information.

If you provide path information for filename, the preprocessor uses that path and does not look for the file in any other directories.

If you do not provide path information and you enclose the filename in angle brackets, the preprocessor searches for the file in:

1) Any directories named with the -i preprocessor option.

2) Any directories set with the environment variable C-DIR.

Note that if you enclose the filename in angle brackets, the preprocessor does not search for the file in the current directory.

C/!) If you do not provide path information and you enclose the filename in double quotes, the preprocessor searches for the file in:

1) The directory that contains the current source file. (The current source file refers to the file that is being processed when the pre-processor encounters the #include directive.)

2) Any directories named with the -i preprocessor option.

3) Any directories set with the environment variable C-DIR.

You can augment the preprocessor's directory search algorithm by using the -i preprocessor option or the environment variable C-DIR.

3.1.3.1 -i Preprocessor Option

3-4

The -i preprocessor option names an alternate directory that contains include files. The format of the -i option is:

gspcpp - ipathname

You can use up to 10 -i options per invocation; each -i option names one pathname. In C source, you can use the #include directive without specifying any path information for the file; instead, you can specify the path information with the -i option. For example, assume that a file called source. c is in the current directory; source. c contains the following directive statement:

#include "alt.c"

The table below lists the complete path name for alt. c and shows how to invoke the preprocessor; select the row for your operating system.

Compiler Operation - Preprocessor Description

DOS:

VMS:

UNIX:

MPW:

Pathname for alto c Invocation Command

c:\gsp\files\alt.c gspcpp -ic:\gsp\files source.c [gsp. files] al t . c gspcpp -i[gsp.files] source.c /gsp/files/alt.c gspcpp -i/gsp/files source.c

:gsp :files :alt .c gspcpp -i :gsp :files source.c Note that the include filename is enclosed in double quotes. The preprocessor first searches for alt. c in the current directory, because source. c is in the current directory. Then, the preprocessor searches the directory named with the -i option.

3.1.3.2 Environment Variable

DOS:

VMS:

UNIX:

MPW:

An environment variable is a system symbol that you define and assign a string to. The preprocessor uses an environment variable named C-DIR to name alternate directories that contain include files. The commands for assigning the environment variable are:

set C-DIR=pathname;another pathname ...

assign "pathname;another pathname ... " C-DIR UNIX: setenv C-DIR "pathname;another pathname '" "

MPW: set C-DIR ":pathname;another: pathname ... "

export C-DIR

The pathnames are directories that contain include files. You can separate pathnames with a semicolon or with blanks. In C source, you can use the

#include directive without specifying any path information; instead, you can specify the path information with C-D I R.

For example, assume that a file called source. c contains these statements:

#include <altl.c>

#include <alt2.c>

The table below lists the complete pathnames for these files and shows how to invoke the preprocessor; select the row for your operating system.

Pathnames for altl. c and alt2.c Invocation Command c:\gsp\files\altl.c

c:\gsys\alt2.c set C-DIR=c:\gsys c:\exec\files gspcpp -ic:\gsp\files source.c [gsp.files]altl.c assign C-DIR " [gsys] [exec.files]"

[gsys]alt2.c gspcpp -i[gsp.files] source.c /gsp/files/altl.c setenv C_DIR "/gsys /exec/files /gsys/alt2.c gspcpp -i\gsp\files source. c I

Compiler Operation - Preprocessor/Parser Description

The environment variable remains set until you reboot the system or reset the variable by entering:

DOS: set C-DIR=

VMS: deassign C-DIR UNIX: setenv C-DIR " "

MPW: unset C-DIR

Dans le document TMS34010 C Compiler (Page 23-27)

Documents relatifs