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