1 .\" $NetBSD: cpp.1,v 1.2 2009/04/30 00:45:47 joerg Exp $
10 .Op Fl D Ns Ar macro Ns = Ns Ar defn...
13 .Op Fl iquote Ns Ar dir...
14 .Op Fl iremap Ns Ar src Ns : Ns Ar dst
15 .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
120 .Bl -tag -width xx -compact
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.
143 .Sy -D'name(args...)=definition'
149 options are processed in the order they are given on the command line.
154 options are processed after all
161 Cancel any previous definition of
163 either built in or provided with a
168 Do not predefine any system-specific or GCC-specific macros.
169 The standard predefined macros remain defined.
174 to the list of directories to be searched for header files.
178 are searched before the standard system include directories.
181 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 .
186 This is the same as specifying
188 as the second non-option argument to
191 has a different interpretation of a second non-option argument, so you must use
193 to specify the output file.
196 Turns on all optional warnings which are desirable for normal code.
201 and a warning about integer promotion causing a change of sign in
204 Note that many of the preprocessor's warnings are on by default and have no options to control them.
208 Warn whenever a comment-start sequence
212 comment, or whenever a backslash-newline appears in a
215 (Both forms have the same effect.)
218 @anchor{Wtrigraphs} Most trigraphs in comments cannot affect the meaning of the program.
219 However, a trigraph that would form an escaped newline
221 at the end of a line) can, by changing where the comment begins or ends.
222 Therefore, only trigraphs that would form escaped newlines produce warnings inside a comment.
224 This option is implied by
228 is not given, this option is still enabled unless trigraphs are enabled.
229 To get trigraph conversion without warnings, but get the other
232 .Fl trigraphs Fl Wall Fl Wno-trigraphs .
235 Warn about certain constructs that behave differently in traditional and ISO C.
236 Also warn about ISO C constructs that have no traditional C equivalent, and problematic constructs which should be avoided.
244 Warn whenever an identifier which is not a macro is encountered in an
246 directive, outside of
248 Such identifiers are replaced with zero.
250 .It Fl Wunused-macros
251 Warn about macros defined in the main file that are unused.
254 if it is expanded or tested for existence at least once.
255 The preprocessor will also warn if the macro has not been used at the time it is redefined or undefined.
257 Built-in macros, macros defined on the command line, and macros defined in include files are not warned about.
260 If a macro is actually used, but only used in skipped conditional blocks, then CPP will report it as unused.
261 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.
262 Alternatively, you could provide a dummy use with something like:
264 .Bd -literal -offset indent
265 #if defined the_macro_causing_the_warning
274 are followed by text.
275 This usually happens in code of the form
277 .Bd -literal -offset indent
286 should be in comments, but often are not in older programs.
287 This warning is on by default.
290 Make all warnings into hard errors.
291 Source code which triggers warnings will be rejected.
293 .It Fl Wsystem-headers
294 Issue warnings for code in system headers.
295 These are normally unhelpful in finding bugs in your own code, therefore suppressed.
296 If you are responsible for the system library, you may want to see them.
299 Suppress all warnings, including those which GNU CPP issues by default.
302 Issue all the mandatory diagnostics listed in the C standard.
303 Some of them are left out by default, since they trigger frequently on harmless code.
305 .It Fl pedantic-errors
306 Issue all the mandatory diagnostics, and make all mandatory diagnostics into errors.
307 This includes mandatory diagnostics that GCC issues without
309 but treats as warnings.
312 Instead of outputting the result of preprocessing, output a rule suitable for
314 describing the dependencies of the main source file.
315 The preprocessor outputs one
317 rule containing the object file name for that source file, a colon, and the names of all the included files, including those coming from
321 command line options.
323 Unless specified explicitly (with
327 the object file name consists of the basename of the source file with any suffix replaced with object file suffix.
328 If there are many included files then the rule is split into several lines using
331 The rule has no commands.
333 This option does not suppress the preprocessor's debug output, such as
335 To avoid mixing such debug output with the dependency rules you should explicitly specify the dependency output file with
337 or use an environment variable like
338 .Sy DEPENDENCIES_OUTPUT .
339 Debug output will still be sent to the regular output stream as normal.
343 to the driver implies
345 and suppresses warnings with an implicit
351 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.
353 This implies that the choice of angle brackets or double quotes in an
355 directive does not in itself determine whether that header will appear in
358 This is a slight change in semantics from GCC versions 3.0 and earlier.
367 specifies a file to write the dependencies to.
370 switch is given the preprocessor sends the rules to the same place it would have sent preprocessed output.
372 When used with the driver options
377 overrides the default dependency output file.
380 In conjunction with an option such as
382 requesting dependency generation,
384 assumes missing header files are generated files and adds them to the dependency list without raising an error.
385 The dependency filename is taken directly from the
387 directive without prepending any path.
389 also suppresses preprocessed output, as a missing header file renders this useless.
391 This feature is used in automatic updating of makefiles.
394 This option instructs CPP to add a phony target for each dependency other than the main file, causing each to depend on nothing.
395 These dummy rules work around errors
397 gives if you remove header files without updating the
401 This is typical output:
403 .Bd -literal -offset indent
404 test.o: test.c test.h
409 Change the target of the rule emitted by dependency generation.
410 By default CPP takes the name of the main input file, including any path, deletes any file suffix such as
412 and appends the platform's usual object suffix.
413 The result is the target.
417 option will set the target to be exactly the string you specify.
418 If you want multiple targets, you can specify them as a single argument to
425 .Sy -MT '$(objpfx)foo.o'
428 .Bd -literal -offset indent
429 $(objpfx)foo.o: foo.c
434 but it quotes any characters which are special to Make.
435 .Sy -MQ '$(objpfx)foo.o'
438 .Bd -literal -offset indent
439 $$(objpfx)foo.o: foo.c
441 The default target is automatically quoted, as if it were given with
447 .Fl M Fl MF Ar file ,
451 The driver determines
456 If it is, the driver uses its argument but with a suffix of
458 otherwise it take the basename of the input file and applies a
464 is used in conjunction with
468 switch is understood to specify the dependency output file (but @pxref{dashMF,,-MF}), but if used without
472 is understood to specify a target object file.
478 can be used to generate a dependency output file as a side-effect of the compilation process.
483 except mention only user header files, not system header files.
487 .It Fl x Ar objective-c
488 .It Fl x Ar assembler-with-cpp
489 Specify the source language: C, C++, Objective-C, or assembly.
490 This has nothing to do with standards conformance or extensions; it merely selects which base syntax to expect.
491 If you give none of these options, cpp will deduce the language from the extension of the source file:
497 Some other common extensions for C++ and assembly are also recognized.
498 If cpp does not recognize the extension, it will treat the file as C; this is the most generic mode.
501 Previous versions of cpp accepted a
503 option which selected both the language and the standards conformance level.
504 This option has been removed, because it conflicts with the
508 .It Fl std= Ns Ar standard
510 Specify the standard to which the code should conform.
511 Currently CPP knows about C and C++ standards; others may be added in the future.
517 .It Sy iso9899:1990 Ns
519 The ISO C standard from 1990.
521 is the customary shorthand for this version of the standard.
525 option is equivalent to
528 .It Sy iso9899:199409 Ns
529 The 1990 C standard, as amended in 1994.
531 .It Sy iso9899:1999 Ns
533 .It Sy iso9899:199x Ns
535 The revised ISO C standard, published in December 1999.
536 Before publication, this was known as C9X.
539 The 1990 C standard plus GNU extensions.
544 The 1999 C standard plus GNU extensions.
547 The 1998 ISO C++ standard plus amendments.
553 This is the default for C++ code.
557 Split the include path.
558 Any directories specified with
562 are searched only for headers requested with
563 .Va .Sy #include \&"file" ;
564 they are not searched for
565 .Va .Sy #include \*[Lt]file\*[Gt] .
566 If additional directories are specified with
570 those directories are searched for all
576 inhibits the use of the directory of the current file directory as the first search directory for
577 .Va .Sy #include \&"file" .
579 This option has been deprecated.
582 Do not search the standard system directories for header files.
583 Only the directories you have specified with
585 options (and the directory of the current file, if appropriate) are searched.
588 Do not search for header files in the C++-specific standard directories, but do still search the other standard directories.
589 (This option is used when building the C++ library.)
591 .It Fl include Ar file
595 .Va #include \&"file"
596 appeared as the first line of the primary source file.
597 However, the first directory searched for
599 is the preprocessor's working directory
601 the directory containing the main source file.
602 If not found there, it is searched for in the remainder of the
604 search chain as normal.
608 options are given, the files are included in the order they appear on the command line.
610 .It Fl imacros Ar file
613 except that any output produced by scanning
616 Macros it defines remain defined.
617 This allows you to acquire all the macros from a header without also processing its declarations.
619 All files specified by
621 are processed before all files specified by
624 .It Fl idirafter Ar dir
627 for header files, but do it
629 all directories specified with
631 and the standard system directories have been exhausted.
633 is treated as a system include directory.
635 .It Fl iprefix Ar prefix
638 as the prefix for subsequent
641 If the prefix represents a directory, you should include the final
644 .It Fl iwithprefix Ar dir
645 .It Fl iwithprefixbefore Ar dir
648 to the prefix specified previously with
650 and add the resulting directory to the include search path.
651 .Fl iwithprefixbefore
652 puts it in the same place
660 .It Fl isysroot Ar dir
661 This option is like the
663 option, but applies only to header files.
666 option for more information.
668 .It Fl isystem Ar dir
671 for header files, after all directories specified by
673 but before the standard system directories.
674 Mark it as a system directory, so that it gets the same special treatment as is applied to the standard system directories.
676 .It Fl cxx-isystem Ar dir
679 for C++ header files, after all directories specified by
681 but before the standard system directories.
682 Mark it as a system directory, so that it gets the same special treatment as is applied to the standard system directories.
687 only for header files requested with
688 .Va .Sy #include \&"file" ;
689 they are not searched for
690 .Va .Sy #include \*[Lt]file\*[Gt] ,
691 before all directories specified by
693 and before the standard system directories.
695 .It Fl iremap Ns Ar src Ns : Ns Ar dst
703 This option can be specified more than once.
704 Processing stops at the first match.
705 .It Fl fdollars-in-identifiers
706 @anchor{fdollars-in-identifiers} Accept
710 .It Fl fextended-identifiers
711 Accept universal character names in identifiers.
712 This option is experimental; in a future version of GCC, it will be enabled by default for C99 and C++.
715 Indicate to the preprocessor that the input file has already been preprocessed.
716 This suppresses things like macro expansion, trigraph conversion, escaped newline splicing, and processing of most directives.
717 The preprocessor still recognizes and removes comments, so that you can pass a file preprocessed with
719 to the compiler without problems.
720 In this mode the integrated preprocessor is little more than a tokenizer for the front ends.
723 is implicit if the input file has one of the extensions
728 These are the extensions that GCC uses for preprocessed files created by
731 .It Fl ftabstop= Ns Ar width
732 Set the distance between tab stops.
733 This helps the preprocessor report correct column numbers in warnings or errors, even if tabs appear on the line.
734 If the value is less than 1 or greater than 100, the option is ignored.
737 .It Fl fexec-charset= Ns Ar charset
738 Set the execution character set, used for string and character constants.
739 The default is UTF-8.
741 can be any encoding supported by the system's
745 .It Fl fwide-exec-charset= Ns Ar charset
746 Set the wide execution character set, used for wide string and character constants.
747 The default is UTF-32 or UTF-16, whichever corresponds to the width of
752 can be any encoding supported by the system's
754 library routine; however, you will have problems with encodings that do not fit exactly in
757 .It Fl finput-charset= Ns Ar charset
758 Set the input character set, used for translation from the character set of the input file to the source character set used by GCC.
759 If the locale does not specify, or GCC cannot get this information from the locale, the default is UTF-8.
760 This can be overridden by either the locale or this command line option.
761 Currently the command line option takes precedence if there's a conflict.
763 can be any encoding supported by the system's
767 .It Fl fworking-directory
768 Enable generation of linemarkers in the preprocessor output that will let the compiler know the current working directory at the time of preprocessing.
769 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.
770 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.
771 This option is implicitly enabled if debugging information is enabled, but this can be inhibited with the negated form
772 .Fl fno-working-directory .
775 flag is present in the command line, this option has no effect, since no
777 directives are emitted whatsoever.
779 .It Fl fno-show-column
780 Do not print column numbers in diagnostics.
781 This may be necessary if diagnostics are being scanned by a program that does not understand the column numbers, such as
784 .It Fl A Ar predicate Ns = Ns Ar answer
785 Make an assertion with the predicate
789 This form is preferred to the older form
794 which is still supported, because it does not use shell special characters.
796 .It Fl A Fl Ns Ar predicate Ns = Ns Ar answer
797 Cancel an assertion with the predicate
804 is a sequence of one or more of the following characters, and must not be preceded by a space.
805 Other characters are interpreted by the compiler proper, or reserved for future versions of GCC, and so are silently ignored.
806 If you specify characters whose behavior conflicts, the result is undefined.
810 Instead of the normal output, generate a list of
812 directives for all the macros defined during the execution of the preprocessor, including predefined macros.
813 This gives you a way of finding out what is predefined in your version of the preprocessor.
814 Assuming you have no file
818 .Bd -literal -offset indent
819 touch foo.h; cpp -dM foo.h
821 will show all the predefined macros.
826 except in two respects: it does
828 include the predefined macros, and it outputs
832 directives and the result of preprocessing.
833 Both kinds of output go to the standard output file.
838 but emit only the macro names, not their expansions.
843 directives in addition to the result of preprocessing.
847 Inhibit generation of linemarkers in the output from the preprocessor.
848 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.
851 Do not discard comments.
852 All comments are passed through to the output file, except for comments in processed directives, which are deleted along with the directive.
854 You should be prepared for side effects when using
856 it causes the preprocessor to treat comments as tokens in their own right.
857 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
861 Do not discard comments, including during macro expansion.
864 except that comments contained within macros are also passed through to the output file where the macro is expanded.
866 In addition to the side-effects of the
870 option causes all C++-style comments inside a macro to be converted to C-style comments.
871 This is to prevent later use of that macro from inadvertently commenting out the remainder of the source line.
875 option is generally used to support lint comments.
877 .It Fl traditional-cpp
878 Try to imitate the behavior of old-fashioned C preprocessors, as opposed to ISO C preprocessors.
881 Process trigraph sequences.
884 Enable special code to work around file systems which only permit very short file names, such as MS-DOS.
888 Print text describing all the command line options instead of preprocessing anything.
892 Print out GNU CPP's version number at the beginning of execution, and report the final form of the include path.
895 Print the name of each header file used, in addition to other normal activities.
896 Each name is indented to show how deep in the
899 Precompiled header files are also printed, even if they are found to be invalid; an invalid precompiled header file is printed with
906 Print out GNU CPP's version number.
907 With one dash, proceed to preprocess as normal.
908 With two dashes, exit immediately.
912 This section describes the environment variables that affect how CPP operates.
913 You can use them to specify directories or prefixes to use when searching for include files, or to control dependency output.
915 Note that you can also specify places to search using options such as
917 and control dependency output with options like
919 These take precedence over environment variables, which in turn take precedence over the configuration of GCC.
921 .Bl -tag -width xx -compact
923 .It Sy C_INCLUDE_PATH Ns
924 .It Sy CPLUS_INCLUDE_PATH Ns
925 .It Sy OBJC_INCLUDE_PATH Ns
926 Each variable's value is a list of directories separated by a special character, much like
928 in which to look for header files.
929 The special character,
931 is target-dependent and determined at GCC build time.
932 For Microsoft Windows-based targets it is a semicolon, and for almost all other targets it is a colon.
935 specifies a list of directories to be searched as if specified with
937 but after any paths given with
939 options on the command line.
940 This environment variable is used regardless of which language is being preprocessed.
942 The remaining environment variables apply only when preprocessing the particular language indicated.
943 Each specifies a list of directories to be searched as if specified with
945 but after any paths given with
947 options on the command line.
949 In all these variables, an empty element instructs the compiler to search its current working directory.
950 Empty elements can appear at the beginning or end of a path.
951 For instance, if the value of
954 .Va :/special/include ,
955 that has the same effect as
956 .Sy -I. -I/special/include .
958 .It Sy DEPENDENCIES_OUTPUT Ns
959 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.
960 System header files are ignored in the dependency output.
963 .Sy DEPENDENCIES_OUTPUT
964 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.
965 Or the value can have the form
969 in which case the rules are written to file
975 In other words, this environment variable is equivalent to combining the options
983 .It Sy SUNPRO_DEPENDENCIES Ns
984 This variable is the same as
985 .Sy DEPENDENCIES_OUTPUT
986 (see above), except that system header files are not ignored, so it implies
990 However, the dependence on the main input file is omitted.
992 .It Sy CPP_RESTRICTED Ns
993 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).
997 gpl(7), gfdl(7), fsf-funding(7), gcc(1), as(1), ld(1), and the Info entries for
1003 Copyright (c) 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
1005 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.
1006 A copy of the license is included in the man page gfdl(7).
1007 This manual contains no Invariant Sections.
1008 The Front-Cover Texts are (a) (see below), and the Back-Cover Texts are (b) (see below).
1010 (a) The FSF's Front-Cover Text is:
1014 (b) The FSF's Back-Cover Text is:
1016 You have freedom to copy and modify this GNU Manual, like GNU software.
1017 Copies published by the Free Software Foundation raise funds for GNU development.