6 cpp - The C Preprocessor
9 .Op Fl D Ns Ar macro Ns = Ns Ar defn...
12 .Op Fl iquote Ns Ar dir...
13 .Op Fl W Ns Ar warn...
20 .Op Fl MQ Ar target...
21 .Op Fl MT Ar target...
23 .Op Fl fno-working-directory
25 .Op Fl std= Ns Ar standard
29 Only the most useful options are listed here; see below for the remainder.
31 The C preprocessor, often known as
35 that is used automatically by the C compiler to transform your program before compilation.
36 It is called a macro processor because it allows you to define
38 which are brief abbreviations for longer constructs.
40 The C preprocessor is intended to be used only with C, C++, and Objective-C source code.
41 In the past, it has been abused as a general text processor.
42 It will choke on input which does not obey C's lexical rules.
43 For example, apostrophes will be interpreted as the beginning of character constants, and cause errors.
44 Also, you cannot rely on it preserving characteristics of the input which are not significant to C-family languages.
45 If a Makefile is preprocessed, all the hard tabs will be removed, and the Makefile will not work.
47 Having said that, you can often get away with using cpp on things which are not C.
48 Other Algol-ish programming languages are often safe (Pascal, Ada, etc.) So is assembly, with caution.
50 mode preserves more white space, and is otherwise more permissive.
51 Many of the problems can be avoided by writing C or C++ style comments instead of native language comments, and keeping macros simple.
53 Wherever possible, you should use a preprocessor geared to the language you are writing in.
54 Modern versions of the GNU assembler have macro facilities.
55 Most high level programming languages have their own conditional compilation and inclusion mechanism.
56 If all else fails, try a true general text processor, such as GNU M4.
58 C preprocessors vary in some details.
59 This manual discusses the GNU C preprocessor, which provides a small superset of the features of ISO Standard C.
60 In its default mode, the GNU C preprocessor does not do a few things required by the standard.
61 These are features which are rarely, if ever, used, and may cause surprising changes to the meaning of a program which does not expect them.
62 To get strict ISO Standard C, you should use the
66 options, depending on which version of the standard you want.
67 To get all the mandatory diagnostics, you must also use
70 This manual describes the behavior of the ISO preprocessor.
71 To minimize gratuitous differences, where the ISO preprocessor's behavior does not conflict with traditional semantics, the traditional preprocessor should behave the same way.
72 The various differences that do exist are detailed in the section
73 .Sy Traditional Mode .
75 For clarity, unless noted otherwise, references to
77 in this manual refer to GNU CPP.
79 The C preprocessor expects two file names as arguments,
83 The preprocessor reads
85 together with any other files it specifies with
87 All the output generated by the combined input files is written in
98 means to read from standard input and as
100 means to write to standard output.
101 Also, if either file is omitted, it means the same as if
103 had been specified for that file.
105 Unless otherwise noted, or the option ends in
107 all options which take an argument may have that argument appear either immediately after the option, or with a space between option and argument:
111 have the same effect.
113 Many options have multi-letter names; therefore multiple single-letter options may
117 is very different from
124 as a macro, with definition
127 .It Fl D Ar name Ns = Ns Ar definition
130 are tokenized and processed as if they appeared during translation phase three in a
133 In particular, the definition will be truncated by embedded newline characters.
135 If you are invoking the preprocessor from a shell or shell-like program you may need to use the shell's quoting syntax to protect characters such as spaces that have a meaning in the shell syntax.
137 If you wish to define a function-like macro on the command line, write its argument list with surrounding parentheses before the equals sign (if any).
138 Parentheses are meaningful to most shells, so you will need to quote the option.
155 options are processed in the order they are given on the command line.
160 options are processed after all
167 Cancel any previous definition of
169 either built in or provided with a
174 Do not predefine any system-specific or GCC-specific macros.
175 The standard predefined macros remain defined.
180 to the list of directories to be searched for header files.
184 are searched before the standard system include directories.
187 is a standard system include directory, the option is ignored to ensure that the default search order for system directories and the special treatment of system headers are not defeated .
192 This is the same as specifying
194 as the second non-option argument to
197 has a different interpretation of a second non-option argument, so you must use
199 to specify the output file.
202 Turns on all optional warnings which are desirable for normal code.
207 and a warning about integer promotion causing a change of sign in
210 Note that many of the preprocessor's warnings are on by default and have no options to control them.
214 Warn whenever a comment-start sequence
218 comment, or whenever a backslash-newline appears in a
221 (Both forms have the same effect.)
224 @anchor{Wtrigraphs} Most trigraphs in comments cannot affect the meaning of the program.
225 However, a trigraph that would form an escaped newline
227 at the end of a line) can, by changing where the comment begins or ends.
228 Therefore, only trigraphs that would form escaped newlines produce warnings inside a comment.
230 This option is implied by
234 is not given, this option is still enabled unless trigraphs are enabled.
235 To get trigraph conversion without warnings, but get the other
238 .Fl trigraphs Fl Wall Fl Wno-trigraphs .
241 Warn about certain constructs that behave differently in traditional and ISO C.
242 Also warn about ISO C constructs that have no traditional C equivalent, and problematic constructs which should be avoided.
250 Warn whenever an identifier which is not a macro is encountered in an
252 directive, outside of
254 Such identifiers are replaced with zero.
256 .It Fl Wunused-macros
257 Warn about macros defined in the main file that are unused.
260 if it is expanded or tested for existence at least once.
261 The preprocessor will also warn if the macro has not been used at the time it is redefined or undefined.
263 Built-in macros, macros defined on the command line, and macros defined in include files are not warned about.
266 If a macro is actually used, but only used in skipped conditional blocks, then CPP will report it as unused.
267 To avoid the warning in such a case, you might improve the scope of the macro's definition by, for example, moving it into the first skipped block.
268 Alternatively, you could provide a dummy use with something like:
270 .Bd -literal -offset indent
271 #if defined the_macro_causing_the_warning
279 are followed by text.
280 This usually happens in code of the form
282 .Bd -literal -offset indent
291 should be in comments, but often are not in older programs.
292 This warning is on by default.
295 Make all warnings into hard errors.
296 Source code which triggers warnings will be rejected.
298 .It Fl Wsystem-headers
299 Issue warnings for code in system headers.
300 These are normally unhelpful in finding bugs in your own code, therefore suppressed.
301 If you are responsible for the system library, you may want to see them.
304 Suppress all warnings, including those which GNU CPP issues by default.
307 Issue all the mandatory diagnostics listed in the C standard.
308 Some of them are left out by default, since they trigger frequently on harmless code.
310 .It Fl pedantic-errors
311 Issue all the mandatory diagnostics, and make all mandatory diagnostics into errors.
312 This includes mandatory diagnostics that GCC issues without
314 but treats as warnings.
317 Instead of outputting the result of preprocessing, output a rule suitable for
319 describing the dependencies of the main source file.
320 The preprocessor outputs one
322 rule containing the object file name for that source file, a colon, and the names of all the included files, including those coming from
326 command line options.
328 Unless specified explicitly (with
332 the object file name consists of the basename of the source file with any suffix replaced with object file suffix.
333 If there are many included files then the rule is split into several lines using
336 The rule has no commands.
338 This option does not suppress the preprocessor's debug output, such as
340 To avoid mixing such debug output with the dependency rules you should explicitly specify the dependency output file with
342 or use an environment variable like
343 .Sy DEPENDENCIES_OUTPUT .
344 Debug output will still be sent to the regular output stream as normal.
348 to the driver implies
350 and suppresses warnings with an implicit
356 but do not mention header files that are found in system header directories, nor header files that are included, directly or indirectly, from such a header.
358 This implies that the choice of angle brackets or double quotes in an
360 directive does not in itself determine whether that header will appear in
363 This is a slight change in semantics from GCC versions 3.0 and earlier.
372 specifies a file to write the dependencies to.
375 switch is given the preprocessor sends the rules to the same place it would have sent preprocessed output.
377 When used with the driver options
382 overrides the default dependency output file.
385 In conjunction with an option such as
387 requesting dependency generation,
389 assumes missing header files are generated files and adds them to the dependency list without raising an error.
390 The dependency filename is taken directly from the
392 directive without prepending any path.
394 also suppresses preprocessed output, as a missing header file renders this useless.
396 This feature is used in automatic updating of makefiles.
399 This option instructs CPP to add a phony target for each dependency other than the main file, causing each to depend on nothing.
400 These dummy rules work around errors
402 gives if you remove header files without updating the
406 This is typical output:
408 .Bd -literal -offset indent
409 test.o: test.c test.h
414 Change the target of the rule emitted by dependency generation.
415 By default CPP takes the name of the main input file, including any path, deletes any file suffix such as
417 and appends the platform's usual object suffix.
418 The result is the target.
422 option will set the target to be exactly the string you specify.
423 If you want multiple targets, you can specify them as a single argument to
430 .Sy -MT '$(objpfx)foo.o'
433 .Bd -literal -offset indent
434 $(objpfx)foo.o: foo.c
439 but it quotes any characters which are special to Make.
440 .Sy -MQ '$(objpfx)foo.o'
443 .Bd -literal -offset indent
444 $$(objpfx)foo.o: foo.c
446 The default target is automatically quoted, as if it were given with
452 .Fl M Fl MF Ar file ,
456 The driver determines
461 If it is, the driver uses its argument but with a suffix of
463 otherwise it take the basename of the input file and applies a
469 is used in conjunction with
473 switch is understood to specify the dependency output file (but @pxref{dashMF,,-MF}), but if used without
477 is understood to specify a target object file.
483 can be used to generate a dependency output file as a side-effect of the compilation process.
488 except mention only user header files, not system header files.
492 .It Fl x Ar objective-c
493 .It Fl x Ar assembler-with-cpp
494 Specify the source language: C, C++, Objective-C, or assembly.
495 This has nothing to do with standards conformance or extensions; it merely selects which base syntax to expect.
496 If you give none of these options, cpp will deduce the language from the extension of the source file:
502 Some other common extensions for C++ and assembly are also recognized.
503 If cpp does not recognize the extension, it will treat the file as C; this is the most generic mode.
506 Previous versions of cpp accepted a
508 option which selected both the language and the standards conformance level.
509 This option has been removed, because it conflicts with the
513 .It Fl std= Ns Ar standard
515 Specify the standard to which the code should conform.
516 Currently CPP knows about C and C++ standards; others may be added in the future.
522 .It Sy iso9899:1990 Ns
524 The ISO C standard from 1990.
526 is the customary shorthand for this version of the standard.
530 option is equivalent to
533 .It Sy iso9899:199409 Ns
534 The 1990 C standard, as amended in 1994.
536 .It Sy iso9899:1999 Ns
538 .It Sy iso9899:199x Ns
540 The revised ISO C standard, published in December 1999.
541 Before publication, this was known as C9X.
544 The 1990 C standard plus GNU extensions.
549 The 1999 C standard plus GNU extensions.
552 The 1998 ISO C++ standard plus amendments.
558 This is the default for C++ code.
562 Split the include path.
563 Any directories specified with
567 are searched only for headers requested with
568 .Va .Sy #include \&"file" ;
569 they are not searched for
570 .Va .Sy #include \*[Lt]file\*[Gt] .
571 If additional directories are specified with
575 those directories are searched for all
581 inhibits the use of the directory of the current file directory as the first search directory for
582 .Va .Sy #include \&"file" .
584 This option has been deprecated.
587 Do not search the standard system directories for header files.
588 Only the directories you have specified with
590 options (and the directory of the current file, if appropriate) are searched.
593 Do not search for header files in the C++-specific standard directories, but do still search the other standard directories.
594 (This option is used when building the C++ library.)
596 .It Fl include Ar file
600 .Va #include \&"file"
601 appeared as the first line of the primary source file.
602 However, the first directory searched for
604 is the preprocessor's working directory
606 the directory containing the main source file.
607 If not found there, it is searched for in the remainder of the
609 search chain as normal.
613 options are given, the files are included in the order they appear on the command line.
615 .It Fl imacros Ar file
618 except that any output produced by scanning
621 Macros it defines remain defined.
622 This allows you to acquire all the macros from a header without also processing its declarations.
624 All files specified by
626 are processed before all files specified by
629 .It Fl idirafter Ar dir
632 for header files, but do it
634 all directories specified with
636 and the standard system directories have been exhausted.
638 is treated as a system include directory.
640 .It Fl iprefix Ar prefix
643 as the prefix for subsequent
646 If the prefix represents a directory, you should include the final
649 .It Fl iwithprefix Ar dir
650 .It Fl iwithprefixbefore Ar dir
653 to the prefix specified previously with
655 and add the resulting directory to the include search path.
656 .Fl iwithprefixbefore
657 puts it in the same place
665 .It Fl isysroot Ar dir
666 This option is like the
668 option, but applies only to header files.
671 option for more information.
673 .It Fl isystem Ar dir
676 for header files, after all directories specified by
678 but before the standard system directories.
679 Mark it as a system directory, so that it gets the same special treatment as is applied to the standard system directories.
681 .It Fl cxx-isystem Ar dir
684 for C++ header files, after all directories specified by
686 but before the standard system directories.
687 Mark it as a system directory, so that it gets the same special treatment as is applied to the standard system directories.
692 only for header files requested with
693 .Va .Sy #include \&"file" ;
694 they are not searched for
695 .Va .Sy #include \*[Lt]file\*[Gt] ,
696 before all directories specified by
698 and before the standard system directories.
700 .It Fl fdollars-in-identifiers
701 @anchor{fdollars-in-identifiers} Accept
705 .It Fl fextended-identifiers
706 Accept universal character names in identifiers.
707 This option is experimental; in a future version of GCC, it will be enabled by default for C99 and C++.
710 Indicate to the preprocessor that the input file has already been preprocessed.
711 This suppresses things like macro expansion, trigraph conversion, escaped newline splicing, and processing of most directives.
712 The preprocessor still recognizes and removes comments, so that you can pass a file preprocessed with
714 to the compiler without problems.
715 In this mode the integrated preprocessor is little more than a tokenizer for the front ends.
718 is implicit if the input file has one of the extensions
723 These are the extensions that GCC uses for preprocessed files created by
726 .It Fl ftabstop= Ns Ar width
727 Set the distance between tab stops.
728 This helps the preprocessor report correct column numbers in warnings or errors, even if tabs appear on the line.
729 If the value is less than 1 or greater than 100, the option is ignored.
732 .It Fl fexec-charset= Ns Ar charset
733 Set the execution character set, used for string and character constants.
734 The default is UTF-8.
736 can be any encoding supported by the system's
740 .It Fl fwide-exec-charset= Ns Ar charset
741 Set the wide execution character set, used for wide string and character constants.
742 The default is UTF-32 or UTF-16, whichever corresponds to the width of
747 can be any encoding supported by the system's
749 library routine; however, you will have problems with encodings that do not fit exactly in
752 .It Fl finput-charset= Ns Ar charset
753 Set the input character set, used for translation from the character set of the input file to the source character set used by GCC.
754 If the locale does not specify, or GCC cannot get this information from the locale, the default is UTF-8.
755 This can be overridden by either the locale or this command line option.
756 Currently the command line option takes precedence if there's a conflict.
758 can be any encoding supported by the system's
762 .It Fl fworking-directory
763 Enable generation of linemarkers in the preprocessor output that will let the compiler know the current working directory at the time of preprocessing.
764 When this option is enabled, the preprocessor will emit, after the initial linemarker, a second linemarker with the current working directory followed by two slashes.
765 GCC will use this directory, when it's present in the preprocessed input, as the directory emitted as the current working directory in some debugging information formats.
766 This option is implicitly enabled if debugging information is enabled, but this can be inhibited with the negated form
767 .Fl fno-working-directory .
770 flag is present in the command line, this option has no effect, since no
772 directives are emitted whatsoever.
774 .It Fl fno-show-column
775 Do not print column numbers in diagnostics.
776 This may be necessary if diagnostics are being scanned by a program that does not understand the column numbers, such as
779 .It Fl A Ar predicate Ns = Ns Ar answer
780 Make an assertion with the predicate
784 This form is preferred to the older form
789 which is still supported, because it does not use shell special characters.
791 .It Fl A Fl Ns Ar predicate Ns = Ns Ar answer
792 Cancel an assertion with the predicate
799 is a sequence of one or more of the following characters, and must not be preceded by a space.
800 Other characters are interpreted by the compiler proper, or reserved for future versions of GCC, and so are silently ignored.
801 If you specify characters whose behavior conflicts, the result is undefined.
805 Instead of the normal output, generate a list of
807 directives for all the macros defined during the execution of the preprocessor, including predefined macros.
808 This gives you a way of finding out what is predefined in your version of the preprocessor.
809 Assuming you have no file
813 .Bd -literal -offset indent
814 touch foo.h; cpp -dM foo.h
816 will show all the predefined macros.
821 except in two respects: it does
823 include the predefined macros, and it outputs
827 directives and the result of preprocessing.
828 Both kinds of output go to the standard output file.
833 but emit only the macro names, not their expansions.
838 directives in addition to the result of preprocessing.
842 Inhibit generation of linemarkers in the output from the preprocessor.
843 This might be useful when running the preprocessor on something that is not C code, and will be sent to a program which might be confused by the linemarkers.
846 Do not discard comments.
847 All comments are passed through to the output file, except for comments in processed directives, which are deleted along with the directive.
849 You should be prepared for side effects when using
851 it causes the preprocessor to treat comments as tokens in their own right.
852 For example, comments appearing at the start of what would be a directive line have the effect of turning that line into an ordinary source line, since the first token on the line is no longer a
856 Do not discard comments, including during macro expansion.
859 except that comments contained within macros are also passed through to the output file where the macro is expanded.
861 In addition to the side-effects of the
865 option causes all C++-style comments inside a macro to be converted to C-style comments.
866 This is to prevent later use of that macro from inadvertently commenting out the remainder of the source line.
870 option is generally used to support lint comments.
872 .It Fl traditional-cpp
873 Try to imitate the behavior of old-fashioned C preprocessors, as opposed to ISO C preprocessors.
876 Process trigraph sequences.
879 Enable special code to work around file systems which only permit very short file names, such as MS-DOS.
883 Print text describing all the command line options instead of preprocessing anything.
887 Print out GNU CPP's version number at the beginning of execution, and report the final form of the include path.
890 Print the name of each header file used, in addition to other normal activities.
891 Each name is indented to show how deep in the
894 Precompiled header files are also printed, even if they are found to be invalid; an invalid precompiled header file is printed with
901 Print out GNU CPP's version number.
902 With one dash, proceed to preprocess as normal.
903 With two dashes, exit immediately.
907 This section describes the environment variables that affect how CPP operates.
908 You can use them to specify directories or prefixes to use when searching for include files, or to control dependency output.
910 Note that you can also specify places to search using options such as
912 and control dependency output with options like
914 These take precedence over environment variables, which in turn take precedence over the configuration of GCC.
918 .It Sy C_INCLUDE_PATH Ns
919 .It Sy CPLUS_INCLUDE_PATH Ns
920 .It Sy OBJC_INCLUDE_PATH Ns
921 Each variable's value is a list of directories separated by a special character, much like
923 in which to look for header files.
924 The special character,
926 is target-dependent and determined at GCC build time.
927 For Microsoft Windows-based targets it is a semicolon, and for almost all other targets it is a colon.
930 specifies a list of directories to be searched as if specified with
932 but after any paths given with
934 options on the command line.
935 This environment variable is used regardless of which language is being preprocessed.
937 The remaining environment variables apply only when preprocessing the particular language indicated.
938 Each specifies a list of directories to be searched as if specified with
940 but after any paths given with
942 options on the command line.
944 In all these variables, an empty element instructs the compiler to search its current working directory.
945 Empty elements can appear at the beginning or end of a path.
946 For instance, if the value of
949 .Va :/special/include ,
950 that has the same effect as
951 .Sy -I. -I/special/include .
953 .It Sy DEPENDENCIES_OUTPUT Ns
954 If this variable is set, its value specifies how to output dependencies for Make based on the non-system header files processed by the compiler.
955 System header files are ignored in the dependency output.
958 .Sy DEPENDENCIES_OUTPUT
959 can be just a file name, in which case the Make rules are written to that file, guessing the target name from the source file name.
960 Or the value can have the form
964 in which case the rules are written to file
970 In other words, this environment variable is equivalent to combining the options
978 .It Sy SUNPRO_DEPENDENCIES Ns
979 This variable is the same as
980 .Sy DEPENDENCIES_OUTPUT
981 (see above), except that system header files are not ignored, so it implies
985 However, the dependence on the main input file is omitted.
987 .It Sy CPP_RESTRICTED Ns
988 If this variable is defined, cpp will skip any include file which is not a regular file, and will continue searching for the requested name (this is always done if the found file is a directory).
992 gpl(7), gfdl(7), fsf-funding(7), gcc(1), as(1), ld(1), and the Info entries for
998 Copyright (c) 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
1000 Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation.
1001 A copy of the license is included in the man page gfdl(7).
1002 This manual contains no Invariant Sections.
1003 The Front-Cover Texts are (a) (see below), and the Back-Cover Texts are (b) (see below).
1005 (a) The FSF's Front-Cover Text is:
1009 (b) The FSF's Back-Cover Text is:
1011 You have freedom to copy and modify this GNU Manual, like GNU software.
1012 Copies published by the Free Software Foundation raise funds for GNU development.