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