Developer Documentation
PATH  Mac OS X Documentation > The GNU C Preprocessor

The GNU C Preprocessor

Previous | Contents | Next

Invoking the C Preprocessor

Usually you won't have to invoke the C preprocessor explicitly, because the C compiler does so automatically. However, there may be times when you want to use the preprocessor by itself by invoking the cpp command.

The cpp and cpp-precomp commands expect two file names as arguments, infile and outfile . The preprocessor reads infile together with any other files that infile specifies by means of  #include or #import . All the output generated by the combined input files is written in  outfile .

Either infile or outfile may be - , which as infile means to read from the standard input and as outfile means to write to the standard output. Also, if outfile or both file names are omitted, the standard output and standard input are used for the omitted file names.

Here's a list of command options accepted by the C preprocessor. Most of them can also be given when compiling a C program; they're passed along automatically to the preprocessor when it's invoked by the compiler.

-P

-P

Inhibit generation of # lines with line-number information in the output from the preprocessor (see the section " See C Preprocessor Output "). This might be useful when running the preprocessor on something that isn't C code and that will be sent to a program which might be confused by the # lines.

-C

-C

Don't discard comments: Pass them through to the output file. Comments appearing in arguments of a macro invocation will be copied to the output before the expansion of the macro.

-traditional

-traditional

Try to imitate the behavior of old-fashioned C, as opposed to ANSI C. Traditional C preprocessing has these characteristics:

-trigraphs

-trigraphs

Process ANSI standard trigraph sequences.

-pedantic

-pedantic

Issue warnings required by the ANSI C standard in certain cases, such as when text other than a comment follows #else or #endif .

-I

-I dir

Add the directory dir to the end of the list of user-supplied directories to be searched for header files (see the section "The #include Command"). This can be used to override a system header file, substituting your own version, since these directories are searched before the system header file directories. If you use more than one -I option, the directories are scanned in left-to-right order; the standard system directories come later.

-I-

-I-

Any directories specified with -I options before the -I- option are searched only for the case of #include " file " ; they aren't searched for #include < file > .

If additional directories are specified with -I options after the -I- , these directories are searched for all #include commands.

In addition, the -I- option inhibits the use of the current directory as the first search directory for #include " file " . Therefore, the current directory is searched only if it's requested explicitly with a -I. option. Specifying both -I- and -I. allows you to control precisely which directories are searched before the current one and which are searched after.

-F

-F dir

Add dir to the end of the list of directories in which to search for frameworks. Directories specified with -F are searched before the standard framework directories.

-nostdinc

-nostdinc

Don't search the standard system directories for header files. Only the directories you specify with -I options (and the current directory, if appropriate) are searched.

-D

-D name

Predefine name as a macro, with definition 1 .

-D name = definition

Predefine name as a macro, with definition definition .

-U name

-U name

Don't predefine name . If both -U and -D are specified for one name, the name won't be predefined.

-undef

-undef

Don't predefine any nonstandard macros.

-d

-d

Produce a list of #define commands for all the macros defined during the execution of the preprocessor, instead of producing the normal preprocessing output.

-M

-M

Produce a rule suitable for make describing the dependencies of the main source file, instead of outputting the result of preprocessing. The preprocessor produces one make rule containing the object file name for that source file, a colon, and the names of all the included files. If there are many included files then the rule is split into several lines using backslash-newline.

This feature is used in automatic updating of makefiles.

-MD

-MD

This is similar to -M , but the dependency information is written to files with names made by replacing ".c" with ".d" at the end of the input file names. This is in addition to compiling the file as specified; -MD doesn't inhibit ordinary compilation the way -M does.

-MM

-MM

This is similar to -M , but mentions only the files included with #include " file " . System header files included with #include < file > are omitted.

-MMD

-MMD

This is similar to -MM , but mentions only user header files, not system header files.

-H

-H

Print the name of each header file used, in addition to other normal activities.

-i

-i file

Process file as input, discarding the resulting output, before processing the regular input file. Because the output generated from file is discarded, the only effect of -i file is to make the macros defined in file available for use in the main input.


The GNU C Preprocessor

Previous | Contents | Next