xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/doc/cppopts.texi (revision e6c7e151de239c49d2e38720a061ed9d1fa99309)
1@c Copyright (C) 1999-2017 Free Software Foundation, Inc.
2@c This is part of the CPP and GCC manuals.
3@c For copying conditions, see the file gcc.texi.
4
5@c ---------------------------------------------------------------------
6@c Options affecting the preprocessor
7@c ---------------------------------------------------------------------
8
9@c If this file is included with the flag ``cppmanual'' set, it is
10@c formatted for inclusion in the CPP manual; otherwise the main GCC manual.
11
12@item -D @var{name}
13@opindex D
14Predefine @var{name} as a macro, with definition @code{1}.
15
16@item -D @var{name}=@var{definition}
17The contents of @var{definition} are tokenized and processed as if
18they appeared during translation phase three in a @samp{#define}
19directive.  In particular, the definition is truncated by
20embedded newline characters.
21
22If you are invoking the preprocessor from a shell or shell-like
23program you may need to use the shell's quoting syntax to protect
24characters such as spaces that have a meaning in the shell syntax.
25
26If you wish to define a function-like macro on the command line, write
27its argument list with surrounding parentheses before the equals sign
28(if any).  Parentheses are meaningful to most shells, so you should
29quote the option.  With @command{sh} and @command{csh},
30@option{-D'@var{name}(@var{args@dots{}})=@var{definition}'} works.
31
32@option{-D} and @option{-U} options are processed in the order they
33are given on the command line.  All @option{-imacros @var{file}} and
34@option{-include @var{file}} options are processed after all
35@option{-D} and @option{-U} options.
36
37@item -U @var{name}
38@opindex U
39Cancel any previous definition of @var{name}, either built in or
40provided with a @option{-D} option.
41
42@item -include @var{file}
43@opindex include
44Process @var{file} as if @code{#include "file"} appeared as the first
45line of the primary source file.  However, the first directory searched
46for @var{file} is the preprocessor's working directory @emph{instead of}
47the directory containing the main source file.  If not found there, it
48is searched for in the remainder of the @code{#include "@dots{}"} search
49chain as normal.
50
51If multiple @option{-include} options are given, the files are included
52in the order they appear on the command line.
53
54@item -imacros @var{file}
55@opindex imacros
56Exactly like @option{-include}, except that any output produced by
57scanning @var{file} is thrown away.  Macros it defines remain defined.
58This allows you to acquire all the macros from a header without also
59processing its declarations.
60
61All files specified by @option{-imacros} are processed before all files
62specified by @option{-include}.
63
64@item -undef
65@opindex undef
66Do not predefine any system-specific or GCC-specific macros.  The
67standard predefined macros remain defined.
68@ifset cppmanual
69@xref{Standard Predefined Macros}.
70@end ifset
71
72@item -pthread
73@opindex pthread
74Define additional macros required for using the POSIX threads library.
75You should use this option consistently for both compilation and linking.
76This option is supported on GNU/Linux targets, most other Unix derivatives,
77and also on x86 Cygwin and MinGW targets.
78
79@item -M
80@opindex M
81@cindex @command{make}
82@cindex dependencies, @command{make}
83Instead of outputting the result of preprocessing, output a rule
84suitable for @command{make} describing the dependencies of the main
85source file.  The preprocessor outputs one @command{make} rule containing
86the object file name for that source file, a colon, and the names of all
87the included files, including those coming from @option{-include} or
88@option{-imacros} command-line options.
89
90Unless specified explicitly (with @option{-MT} or @option{-MQ}), the
91object file name consists of the name of the source file with any
92suffix replaced with object file suffix and with any leading directory
93parts removed.  If there are many included files then the rule is
94split into several lines using @samp{\}-newline.  The rule has no
95commands.
96
97This option does not suppress the preprocessor's debug output, such as
98@option{-dM}.  To avoid mixing such debug output with the dependency
99rules you should explicitly specify the dependency output file with
100@option{-MF}, or use an environment variable like
101@env{DEPENDENCIES_OUTPUT} (@pxref{Environment Variables}).  Debug output
102is still sent to the regular output stream as normal.
103
104Passing @option{-M} to the driver implies @option{-E}, and suppresses
105warnings with an implicit @option{-w}.
106
107@item -MM
108@opindex MM
109Like @option{-M} but do not mention header files that are found in
110system header directories, nor header files that are included,
111directly or indirectly, from such a header.
112
113This implies that the choice of angle brackets or double quotes in an
114@samp{#include} directive does not in itself determine whether that
115header appears in @option{-MM} dependency output.
116
117@anchor{dashMF}
118@item -MF @var{file}
119@opindex MF
120When used with @option{-M} or @option{-MM}, specifies a
121file to write the dependencies to.  If no @option{-MF} switch is given
122the preprocessor sends the rules to the same place it would send
123preprocessed output.
124
125When used with the driver options @option{-MD} or @option{-MMD},
126@option{-MF} overrides the default dependency output file.
127
128@item -MG
129@opindex MG
130In conjunction with an option such as @option{-M} requesting
131dependency generation, @option{-MG} assumes missing header files are
132generated files and adds them to the dependency list without raising
133an error.  The dependency filename is taken directly from the
134@code{#include} directive without prepending any path.  @option{-MG}
135also suppresses preprocessed output, as a missing header file renders
136this useless.
137
138This feature is used in automatic updating of makefiles.
139
140@item -MP
141@opindex MP
142This option instructs CPP to add a phony target for each dependency
143other than the main file, causing each to depend on nothing.  These
144dummy rules work around errors @command{make} gives if you remove header
145files without updating the @file{Makefile} to match.
146
147This is typical output:
148
149@smallexample
150test.o: test.c test.h
151
152test.h:
153@end smallexample
154
155@item -MT @var{target}
156@opindex MT
157
158Change the target of the rule emitted by dependency generation.  By
159default CPP takes the name of the main input file, deletes any
160directory components and any file suffix such as @samp{.c}, and
161appends the platform's usual object suffix.  The result is the target.
162
163An @option{-MT} option sets the target to be exactly the string you
164specify.  If you want multiple targets, you can specify them as a single
165argument to @option{-MT}, or use multiple @option{-MT} options.
166
167For example, @option{@w{-MT '$(objpfx)foo.o'}} might give
168
169@smallexample
170$(objpfx)foo.o: foo.c
171@end smallexample
172
173@item -MQ @var{target}
174@opindex MQ
175
176Same as @option{-MT}, but it quotes any characters which are special to
177Make.  @option{@w{-MQ '$(objpfx)foo.o'}} gives
178
179@smallexample
180$$(objpfx)foo.o: foo.c
181@end smallexample
182
183The default target is automatically quoted, as if it were given with
184@option{-MQ}.
185
186@item -MD
187@opindex MD
188@option{-MD} is equivalent to @option{-M -MF @var{file}}, except that
189@option{-E} is not implied.  The driver determines @var{file} based on
190whether an @option{-o} option is given.  If it is, the driver uses its
191argument but with a suffix of @file{.d}, otherwise it takes the name
192of the input file, removes any directory components and suffix, and
193applies a @file{.d} suffix.
194
195If @option{-MD} is used in conjunction with @option{-E}, any
196@option{-o} switch is understood to specify the dependency output file
197(@pxref{dashMF,,-MF}), but if used without @option{-E}, each @option{-o}
198is understood to specify a target object file.
199
200Since @option{-E} is not implied, @option{-MD} can be used to generate
201a dependency output file as a side-effect of the compilation process.
202
203@item -MMD
204@opindex MMD
205Like @option{-MD} except mention only user header files, not system
206header files.
207
208@item -fpreprocessed
209@opindex fpreprocessed
210Indicate to the preprocessor that the input file has already been
211preprocessed.  This suppresses things like macro expansion, trigraph
212conversion, escaped newline splicing, and processing of most directives.
213The preprocessor still recognizes and removes comments, so that you can
214pass a file preprocessed with @option{-C} to the compiler without
215problems.  In this mode the integrated preprocessor is little more than
216a tokenizer for the front ends.
217
218@option{-fpreprocessed} is implicit if the input file has one of the
219extensions @samp{.i}, @samp{.ii} or @samp{.mi}.  These are the
220extensions that GCC uses for preprocessed files created by
221@option{-save-temps}.
222
223@item -cxx-isystem @var{dir}
224@opindex cxxisystem
225Search @var{dir} for C++ header files, after all directories specified by
226@option{-I} but before the standard system directories.  Mark it
227as a system directory, so that it gets the same special treatment as
228is applied to the standard system directories.
229@ifset cppmanual
230@xref{System Headers}.
231@end ifset
232
233@item -fdirectives-only
234@opindex fdirectives-only
235When preprocessing, handle directives, but do not expand macros.
236
237The option's behavior depends on the @option{-E} and @option{-fpreprocessed}
238options.
239
240With @option{-E}, preprocessing is limited to the handling of directives
241such as @code{#define}, @code{#ifdef}, and @code{#error}.  Other
242preprocessor operations, such as macro expansion and trigraph
243conversion are not performed.  In addition, the @option{-dD} option is
244implicitly enabled.
245
246With @option{-fpreprocessed}, predefinition of command line and most
247builtin macros is disabled.  Macros such as @code{__LINE__}, which are
248contextually dependent, are handled normally.  This enables compilation of
249files previously preprocessed with @code{-E -fdirectives-only}.
250
251With both @option{-E} and @option{-fpreprocessed}, the rules for
252@option{-fpreprocessed} take precedence.  This enables full preprocessing of
253files previously preprocessed with @code{-E -fdirectives-only}.
254
255@item -iremap @var{src}:@var{dst}
256@opindex iremap
257Replace the prefix @var{src} in __FILE__ with @var{dst} at expansion time.
258This option can be specified more than once.  Processing stops at the first
259match.
260
261@item -fdollars-in-identifiers
262@opindex fdollars-in-identifiers
263@anchor{fdollars-in-identifiers}
264Accept @samp{$} in identifiers.
265@ifset cppmanual
266@xref{Identifier characters}.
267@end ifset
268
269@item -fextended-identifiers
270@opindex fextended-identifiers
271Accept universal character names in identifiers.  This option is
272enabled by default for C99 (and later C standard versions) and C++.
273
274@item -fno-canonical-system-headers
275@opindex fno-canonical-system-headers
276When preprocessing, do not shorten system header paths with canonicalization.
277
278@item -ftabstop=@var{width}
279@opindex ftabstop
280Set the distance between tab stops.  This helps the preprocessor report
281correct column numbers in warnings or errors, even if tabs appear on the
282line.  If the value is less than 1 or greater than 100, the option is
283ignored.  The default is 8.
284
285@item -ftrack-macro-expansion@r{[}=@var{level}@r{]}
286@opindex ftrack-macro-expansion
287Track locations of tokens across macro expansions. This allows the
288compiler to emit diagnostic about the current macro expansion stack
289when a compilation error occurs in a macro expansion. Using this
290option makes the preprocessor and the compiler consume more
291memory. The @var{level} parameter can be used to choose the level of
292precision of token location tracking thus decreasing the memory
293consumption if necessary. Value @samp{0} of @var{level} de-activates
294this option. Value @samp{1} tracks tokens locations in a
295degraded mode for the sake of minimal memory overhead. In this mode
296all tokens resulting from the expansion of an argument of a
297function-like macro have the same location. Value @samp{2} tracks
298tokens locations completely. This value is the most memory hungry.
299When this option is given no argument, the default parameter value is
300@samp{2}.
301
302Note that @code{-ftrack-macro-expansion=2} is activated by default.
303
304@item -fexec-charset=@var{charset}
305@opindex fexec-charset
306@cindex character set, execution
307Set the execution character set, used for string and character
308constants.  The default is UTF-8.  @var{charset} can be any encoding
309supported by the system's @code{iconv} library routine.
310
311@item -fwide-exec-charset=@var{charset}
312@opindex fwide-exec-charset
313@cindex character set, wide execution
314Set the wide execution character set, used for wide string and
315character constants.  The default is UTF-32 or UTF-16, whichever
316corresponds to the width of @code{wchar_t}.  As with
317@option{-fexec-charset}, @var{charset} can be any encoding supported
318by the system's @code{iconv} library routine; however, you will have
319problems with encodings that do not fit exactly in @code{wchar_t}.
320
321@item -finput-charset=@var{charset}
322@opindex finput-charset
323@cindex character set, input
324Set the input character set, used for translation from the character
325set of the input file to the source character set used by GCC@.  If the
326locale does not specify, or GCC cannot get this information from the
327locale, the default is UTF-8.  This can be overridden by either the locale
328or this command-line option.  Currently the command-line option takes
329precedence if there's a conflict.  @var{charset} can be any encoding
330supported by the system's @code{iconv} library routine.
331
332@ifclear cppmanual
333@item -fpch-deps
334@opindex fpch-deps
335When using precompiled headers (@pxref{Precompiled Headers}), this flag
336causes the dependency-output flags to also list the files from the
337precompiled header's dependencies.  If not specified, only the
338precompiled header are listed and not the files that were used to
339create it, because those files are not consulted when a precompiled
340header is used.
341
342@item -fpch-preprocess
343@opindex fpch-preprocess
344This option allows use of a precompiled header (@pxref{Precompiled
345Headers}) together with @option{-E}.  It inserts a special @code{#pragma},
346@code{#pragma GCC pch_preprocess "@var{filename}"} in the output to mark
347the place where the precompiled header was found, and its @var{filename}.
348When @option{-fpreprocessed} is in use, GCC recognizes this @code{#pragma}
349and loads the PCH@.
350
351This option is off by default, because the resulting preprocessed output
352is only really suitable as input to GCC@.  It is switched on by
353@option{-save-temps}.
354
355You should not write this @code{#pragma} in your own code, but it is
356safe to edit the filename if the PCH file is available in a different
357location.  The filename may be absolute or it may be relative to GCC's
358current directory.
359@end ifclear
360
361@item -fworking-directory
362@opindex fworking-directory
363@opindex fno-working-directory
364Enable generation of linemarkers in the preprocessor output that
365let the compiler know the current working directory at the time of
366preprocessing.  When this option is enabled, the preprocessor
367emits, after the initial linemarker, a second linemarker with the
368current working directory followed by two slashes.  GCC uses this
369directory, when it's present in the preprocessed input, as the
370directory emitted as the current working directory in some debugging
371information formats.  This option is implicitly enabled if debugging
372information is enabled, but this can be inhibited with the negated
373form @option{-fno-working-directory}.  If the @option{-P} flag is
374present in the command line, this option has no effect, since no
375@code{#line} directives are emitted whatsoever.
376
377@item -A @var{predicate}=@var{answer}
378@opindex A
379Make an assertion with the predicate @var{predicate} and answer
380@var{answer}.  This form is preferred to the older form @option{-A
381@var{predicate}(@var{answer})}, which is still supported, because
382it does not use shell special characters.
383@ifset cppmanual
384@xref{Obsolete Features}.
385@end ifset
386
387@item -A -@var{predicate}=@var{answer}
388Cancel an assertion with the predicate @var{predicate} and answer
389@var{answer}.
390
391@item -C
392@opindex C
393Do not discard comments.  All comments are passed through to the output
394file, except for comments in processed directives, which are deleted
395along with the directive.
396
397You should be prepared for side effects when using @option{-C}; it
398causes the preprocessor to treat comments as tokens in their own right.
399For example, comments appearing at the start of what would be a
400directive line have the effect of turning that line into an ordinary
401source line, since the first token on the line is no longer a @samp{#}.
402
403@item -CC
404@opindex CC
405Do not discard comments, including during macro expansion.  This is
406like @option{-C}, except that comments contained within macros are
407also passed through to the output file where the macro is expanded.
408
409In addition to the side-effects of the @option{-C} option, the
410@option{-CC} option causes all C++-style comments inside a macro
411to be converted to C-style comments.  This is to prevent later use
412of that macro from inadvertently commenting out the remainder of
413the source line.
414
415The @option{-CC} option is generally used to support lint comments.
416
417@item -P
418@opindex P
419Inhibit generation of linemarkers in the output from the preprocessor.
420This might be useful when running the preprocessor on something that is
421not C code, and will be sent to a program which might be confused by the
422linemarkers.
423@ifset cppmanual
424@xref{Preprocessor Output}.
425@end ifset
426
427@cindex traditional C language
428@cindex C language, traditional
429@item -traditional
430@itemx -traditional-cpp
431@opindex traditional-cpp
432@opindex traditional
433
434Try to imitate the behavior of pre-standard C preprocessors, as
435opposed to ISO C preprocessors.
436@ifset cppmanual
437@xref{Traditional Mode}.
438@end ifset
439@ifclear cppmanual
440See the GNU CPP manual for details.
441@end ifclear
442
443Note that GCC does not otherwise attempt to emulate a pre-standard
444C compiler, and these options are only supported with the @option{-E}
445switch, or when invoking CPP explicitly.
446
447@item -trigraphs
448@opindex trigraphs
449Support ISO C trigraphs.
450These are three-character sequences, all starting with @samp{??}, that
451are defined by ISO C to stand for single characters.  For example,
452@samp{??/} stands for @samp{\}, so @samp{'??/n'} is a character
453constant for a newline.
454@ifset cppmanual
455@xref{Initial processing}.
456@end ifset
457
458@ifclear cppmanual
459The nine trigraphs and their replacements are
460
461@smallexample
462Trigraph:       ??(  ??)  ??<  ??>  ??=  ??/  ??'  ??!  ??-
463Replacement:      [    ]    @{    @}    #    \    ^    |    ~
464@end smallexample
465@end ifclear
466
467By default, GCC ignores trigraphs, but in
468standard-conforming modes it converts them.  See the @option{-std} and
469@option{-ansi} options.
470
471@item -remap
472@opindex remap
473Enable special code to work around file systems which only permit very
474short file names, such as MS-DOS@.
475
476@item -H
477@opindex H
478Print the name of each header file used, in addition to other normal
479activities.  Each name is indented to show how deep in the
480@samp{#include} stack it is.  Precompiled header files are also
481printed, even if they are found to be invalid; an invalid precompiled
482header file is printed with @samp{...x} and a valid one with @samp{...!} .
483
484@item -d@var{letters}
485@opindex d
486Says to make debugging dumps during compilation as specified by
487@var{letters}.  The flags documented here are those relevant to the
488preprocessor.  Other @var{letters} are interpreted
489by the compiler proper, or reserved for future versions of GCC, and so
490are silently ignored.  If you specify @var{letters} whose behavior
491conflicts, the result is undefined.
492@ifclear cppmanual
493@xref{Developer Options}, for more information.
494@end ifclear
495
496@table @gcctabopt
497@item -dM
498@opindex dM
499Instead of the normal output, generate a list of @samp{#define}
500directives for all the macros defined during the execution of the
501preprocessor, including predefined macros.  This gives you a way of
502finding out what is predefined in your version of the preprocessor.
503Assuming you have no file @file{foo.h}, the command
504
505@smallexample
506touch foo.h; cpp -dM foo.h
507@end smallexample
508
509@noindent
510shows all the predefined macros.
511
512@ifclear cppmanual
513If you use @option{-dM} without the @option{-E} option, @option{-dM} is
514interpreted as a synonym for @option{-fdump-rtl-mach}.
515@xref{Developer Options, , ,gcc}.
516@end ifclear
517
518@item -dD
519@opindex dD
520Like @option{-dM} except in two respects: it does @emph{not} include the
521predefined macros, and it outputs @emph{both} the @samp{#define}
522directives and the result of preprocessing.  Both kinds of output go to
523the standard output file.
524
525@item -dN
526@opindex dN
527Like @option{-dD}, but emit only the macro names, not their expansions.
528
529@item -dI
530@opindex dI
531Output @samp{#include} directives in addition to the result of
532preprocessing.
533
534@item -dU
535@opindex dU
536Like @option{-dD} except that only macros that are expanded, or whose
537definedness is tested in preprocessor directives, are output; the
538output is delayed until the use or test of the macro; and
539@samp{#undef} directives are also output for macros tested but
540undefined at the time.
541@end table
542
543@item -fdebug-cpp
544@opindex fdebug-cpp
545This option is only useful for debugging GCC.  When used from CPP or with
546@option{-E}, it dumps debugging information about location maps.  Every
547token in the output is preceded by the dump of the map its location
548belongs to.
549
550When used from GCC without @option{-E}, this option has no effect.
551
552