* doc/cppopts.texi: Enhance -Wtrigraphs documentation
[platform/upstream/gcc.git] / gcc / doc / cppopts.texi
1 @c Copyright (c) 1999, 2000, 2001, 2002
2 @c Free Software Foundation, Inc.
3 @c This is part of the CPP and GCC manuals.
4 @c For copying conditions, see the file gcc.texi.
5
6 @c ---------------------------------------------------------------------
7 @c Options affecting the preprocessor
8 @c ---------------------------------------------------------------------
9
10 @c If this file is included with the flag ``cppmanual'' set, it is
11 @c formatted for inclusion in the CPP manual; otherwise the main GCC manual.
12
13 @table @gcctabopt
14 @item -D @var{name}
15 @opindex D
16 Predefine @var{name} as a macro, with definition @code{1}.
17
18 @item -D @var{name}=@var{definition}
19 Predefine @var{name} as a macro, with definition @var{definition}.
20 There are no restrictions on the contents of @var{definition}, but if
21 you are invoking the preprocessor from a shell or shell-like program you
22 may need to use the shell's quoting syntax to protect characters such as
23 spaces that have a meaning in the shell syntax.
24
25 If you wish to define a function-like macro on the command line, write
26 its argument list with surrounding parentheses before the equals sign
27 (if any).  Parentheses are meaningful to most shells, so you will need
28 to quote the option.  With @command{sh} and @command{csh},
29 @option{-D'@var{name}(@var{args@dots{}})=@var{definition}'} works.
30
31 @option{-D} and @option{-U} options are processed in the order they
32 are given on the command line.  All @option{-imacros @var{file}} and
33 @option{-include @var{file}} options are processed after all
34 @option{-D} and @option{-U} options.
35
36 @item -U @var{name}
37 @opindex U
38 Cancel any previous definition of @var{name}, either built in or
39 provided with a @option{-D} option.
40
41 @item -undef
42 @opindex undef
43 Do not predefine any system-specific macros.  The common predefined
44 macros remain defined.
45
46 @item -I @var{dir}
47 @opindex I
48 Add the directory @var{dir} to the list of directories to be searched
49 for header files.
50 @ifset cppmanual
51 @xref{Search Path}.
52 @end ifset
53 Directories named by @option{-I} are searched before the standard
54 system include directories.  If the directory @var{dir} is a standard
55 system include directory, the option is ignored to ensure that the
56 default search order for system directories and the special treatment
57 of system headers are not defeated
58 @ifset cppmanual
59 (@pxref{System Headers})
60 @end ifset
61 .
62
63 @item -o @var{file}
64 @opindex o
65 Write output to @var{file}.  This is the same as specifying @var{file}
66 as the second non-option argument to @command{cpp}.  @command{gcc} has a
67 different interpretation of a second non-option argument, so you must
68 use @option{-o} to specify the output file.
69
70 @item -Wall
71 @opindex Wall
72 Turns on all optional warnings which are desirable for normal code.
73 At present this is @option{-Wcomment}, @option{-Wtrigraphs},
74 @option{-Wmultichar} and a warning about integer promotion causing a
75 change of sign in @code{#if} expressions.  Note that many of the
76 preprocessor's warnings are on by default and have no options to
77 control them.
78
79 @item -Wcomment
80 @itemx -Wcomments
81 @opindex Wcomment
82 @opindex Wcomments
83 Warn whenever a comment-start sequence @samp{/*} appears in a @samp{/*}
84 comment, or whenever a backslash-newline appears in a @samp{//} comment.
85 (Both forms have the same effect.)
86
87 @item -Wtrigraphs
88 @opindex Wtrigraphs
89 @anchor{Wtrigraphs}
90 Most trigraphs in comments cannot affect the meaning of the program.
91 However, a trigraph that would form an escaped newline (@samp{??/} at
92 the end of a line) can, by changing where the comment begins or ends.
93 Therefore, only trigraphs that would form escaped newlines produce
94 warnings inside a comment.
95
96 This option is implied by @option{-Wall}.  If @option{-Wall} is not
97 given, this option is still enabled unless trigraphs are enabled.  To
98 get trigraph conversion without warnings, but get the other
99 @option{-Wall} warnings, use @samp{-trigraphs -Wall -Wno-trigraphs}.
100
101 @item -Wtraditional
102 @opindex Wtraditional
103 Warn about certain constructs that behave differently in traditional and
104 ISO C@.  Also warn about ISO C constructs that have no traditional C
105 equivalent, and problematic constructs which should be avoided.
106 @ifset cppmanual
107 @xref{Traditional Mode}.
108 @end ifset
109
110 @item -Wimport
111 @opindex Wimport
112 Warn the first time @samp{#import} is used.
113
114 @item -Wundef
115 @opindex Wundef
116 Warn whenever an identifier which is not a macro is encountered in an
117 @samp{#if} directive, outside of @samp{defined}.  Such identifiers are
118 replaced with zero.
119
120 @item -Wunused-macros
121 @opindex Wunused-macros
122 Warn about macros defined in the main file that are unused.  A macro
123 is @dfn{used} if it is expanded or tested for existence at least once.
124 The preprocessor will also warn if the macro has not been used at the
125 time it is redefined or undefined.
126
127 Built-in macros, macros defined on the command line, and macros
128 defined in include files are not warned about.
129
130 @strong{Note:} If a macro is actually used, but only used in skipped
131 conditional blocks, then CPP will report it as unused.  To avoid the
132 warning in such a case, you might improve the scope of the macro's
133 definition by, for example, moving it into the first skipped block.
134 Alternatively, you could provide a dummy use with something like:
135
136 @smallexample
137 #if defined the_macro_causing_the_warning
138 #endif
139 @end smallexample
140
141 @item -Wendif-labels
142 @opindex Wendif-labels
143 Warn whenever an @samp{#else} or an @samp{#endif} are followed by text.
144 This usually happens in code of the form
145
146 @smallexample
147 #if FOO
148 @dots{}
149 #else FOO
150 @dots{}
151 #endif FOO
152 @end smallexample
153
154 @noindent
155 The second and third @code{FOO} should be in comments, but often are not
156 in older programs.  This warning is on by default.
157
158 @item -Werror
159 @opindex Werror
160 Make all warnings into hard errors.  Source code which triggers warnings
161 will be rejected.
162
163 @item -Wsystem-headers
164 @opindex Wsystem-headers
165 Issue warnings for code in system headers.  These are normally unhelpful
166 in finding bugs in your own code, therefore suppressed.  If you are
167 responsible for the system library, you may want to see them.
168
169 @item -w
170 @opindex w
171 Suppress all warnings, including those which GNU CPP issues by default.
172
173 @item -pedantic
174 @opindex pedantic
175 Issue all the mandatory diagnostics listed in the C standard.  Some of
176 them are left out by default, since they trigger frequently on harmless
177 code.
178
179 @item -pedantic-errors
180 @opindex pedantic-errors
181 Issue all the mandatory diagnostics, and make all mandatory diagnostics
182 into errors.  This includes mandatory diagnostics that GCC issues
183 without @samp{-pedantic} but treats as warnings.
184
185 @item -M
186 @opindex M
187 @cindex make
188 @cindex dependencies, make
189 Instead of outputting the result of preprocessing, output a rule
190 suitable for @command{make} describing the dependencies of the main
191 source file.  The preprocessor outputs one @command{make} rule containing
192 the object file name for that source file, a colon, and the names of all
193 the included files, including those coming from @option{-include} or
194 @option{-imacros} command line options.
195
196 Unless specified explicitly (with @option{-MT} or @option{-MQ}), the
197 object file name consists of the basename of the source file with any
198 suffix replaced with object file suffix.  If there are many included
199 files then the rule is split into several lines using @samp{\}-newline.
200 The rule has no commands.
201
202 This option does not suppress the preprocessor's debug output, such as
203 @option{-dM}.  To avoid mixing such debug output with the dependency
204 rules you should explicitly specify the dependency output file with
205 @option{-MF}, or use an environment variable like
206 @env{DEPENDENCIES_OUTPUT} (@pxref{Environment Variables}).  Debug output
207 will still be sent to the regular output stream as normal.
208
209 Passing @option{-M} to the driver implies @option{-E}, and suppresses
210 warnings with an implicit @option{-w}.
211
212 @item -MM
213 @opindex MM
214 Like @option{-M} but do not mention header files that are found in
215 system header directories, nor header files that are included,
216 directly or indirectly, from such a header.
217
218 This implies that the choice of angle brackets or double quotes in an
219 @samp{#include} directive does not in itself determine whether that
220 header will appear in @option{-MM} dependency output.  This is a
221 slight change in semantics from GCC versions 3.0 and earlier.
222
223 @item -MF @var{file}
224 @opindex MF
225 @anchor{-MF}
226 When used with @option{-M} or @option{-MM}, specifies a
227 file to write the dependencies to.  If no @option{-MF} switch is given
228 the preprocessor sends the rules to the same place it would have sent
229 preprocessed output.
230
231 When used with the driver options @option{-MD} or @option{-MMD},
232 @option{-MF} overrides the default dependency output file.
233
234 @item -MG
235 @opindex MG
236 In conjunction with an option such as @option{-M} requesting
237 dependency generation, @option{-MG} assumes missing header files are
238 generated files and adds them to the dependency list without raising
239 an error.  The dependency filename is taken directly from the
240 @code{#include} directive without prepending any path.  @option{-MG}
241 also suppresses preprocessed output, as a missing header file renders
242 this useless.
243
244 This feature is used in automatic updating of makefiles.
245
246 @item -MP
247 @opindex MP
248 This option instructs CPP to add a phony target for each dependency
249 other than the main file, causing each to depend on nothing.  These
250 dummy rules work around errors @command{make} gives if you remove header
251 files without updating the @file{Makefile} to match.
252
253 This is typical output:
254
255 @example
256 test.o: test.c test.h
257
258 test.h:
259 @end example
260
261 @item -MT @var{target}
262 @opindex MT
263
264 Change the target of the rule emitted by dependency generation.  By
265 default CPP takes the name of the main input file, including any path,
266 deletes any file suffix such as @samp{.c}, and appends the platform's
267 usual object suffix.  The result is the target.
268
269 An @option{-MT} option will set the target to be exactly the string you
270 specify.  If you want multiple targets, you can specify them as a single
271 argument to @option{-MT}, or use multiple @option{-MT} options.
272
273 For example, @option{@w{-MT '$(objpfx)foo.o'}} might give
274
275 @example
276 $(objpfx)foo.o: foo.c
277 @end example
278
279 @item -MQ @var{target}
280 @opindex MQ
281
282 Same as @option{-MT}, but it quotes any characters which are special to
283 Make.  @option{@w{-MQ '$(objpfx)foo.o'}} gives
284
285 @example
286 $$(objpfx)foo.o: foo.c
287 @end example
288
289 The default target is automatically quoted, as if it were given with
290 @option{-MQ}.
291
292 @item -MD
293 @opindex MD
294 @option{-MD} is equivalent to @option{-M -MF @var{file}}, except that
295 @option{-E} is not implied.  The driver determines @var{file} based on
296 whether an @option{-o} option is given.  If it is, the driver uses its
297 argument but with a suffix of @file{.d}, otherwise it take the
298 basename of the input file and applies a @file{.d} suffix.
299
300 If @option{-MD} is used in conjunction with @option{-E}, any
301 @option{-o} switch is understood to specify the dependency output file
302 (but @pxref{-MF}), but if used without @option{-E}, each @option{-o}
303 is understood to specify a target object file.
304
305 Since @option{-E} is not implied, @option{-MD} can be used to generate
306 a dependency output file as a side-effect of the compilation process.
307
308 @item -MMD
309 @opindex MMD
310 Like @option{-MD} except mention only user header files, not system
311 -header files.
312
313 @ifclear cppmanual
314 @item -fpch-deps
315 @opindex fpch-deps
316 When using precompiled headers (@pxref{Precompiled Headers}), this flag
317 will cause the dependency-output flags to also list the files from the
318 precompiled header's dependencies.  If not specified only the
319 precompiled header would be listed and not the files that were used to
320 create it because those files are not consulted when a precompiled
321 header is used.
322
323 @end ifclear
324 @item -x c
325 @itemx -x c++
326 @itemx -x objective-c
327 @itemx -x assembler-with-cpp
328 @opindex x
329 Specify the source language: C, C++, Objective-C, or assembly.  This has
330 nothing to do with standards conformance or extensions; it merely
331 selects which base syntax to expect.  If you give none of these options,
332 cpp will deduce the language from the extension of the source file:
333 @samp{.c}, @samp{.cc}, @samp{.m}, or @samp{.S}.  Some other common
334 extensions for C++ and assembly are also recognized.  If cpp does not
335 recognize the extension, it will treat the file as C; this is the most
336 generic mode.
337
338 @strong{Note:} Previous versions of cpp accepted a @option{-lang} option
339 which selected both the language and the standards conformance level.
340 This option has been removed, because it conflicts with the @option{-l}
341 option.
342
343 @item -std=@var{standard}
344 @itemx -ansi
345 @opindex ansi
346 @opindex std=
347 Specify the standard to which the code should conform.  Currently CPP
348 knows about C and C++ standards; others may be added in the future.
349
350 @var{standard}
351 may be one of:
352 @table @code
353 @item iso9899:1990
354 @itemx c89
355 The ISO C standard from 1990.  @samp{c89} is the customary shorthand for
356 this version of the standard.
357
358 The @option{-ansi} option is equivalent to @option{-std=c89}.
359
360 @item iso9899:199409
361 The 1990 C standard, as amended in 1994.
362
363 @item iso9899:1999
364 @itemx c99
365 @itemx iso9899:199x
366 @itemx c9x
367 The revised ISO C standard, published in December 1999.  Before
368 publication, this was known as C9X@.
369
370 @item gnu89
371 The 1990 C standard plus GNU extensions.  This is the default.
372
373 @item gnu99
374 @itemx gnu9x
375 The 1999 C standard plus GNU extensions.
376
377 @item c++98
378 The 1998 ISO C++ standard plus amendments.
379
380 @item gnu++98
381 The same as @option{-std=c++98} plus GNU extensions.  This is the
382 default for C++ code.
383 @end table
384
385 @item -I-
386 @opindex I-
387 Split the include path.  Any directories specified with @option{-I}
388 options before @option{-I-} are searched only for headers requested with
389 @code{@w{#include "@var{file}"}}; they are not searched for
390 @code{@w{#include <@var{file}>}}.  If additional directories are
391 specified with @option{-I} options after the @option{-I-}, those
392 directories are searched for all @samp{#include} directives.
393
394 In addition, @option{-I-} inhibits the use of the directory of the current
395 file directory as the first search directory for @code{@w{#include
396 "@var{file}"}}.
397 @ifset cppmanual
398 @xref{Search Path}.
399 @end ifset
400
401 @item -nostdinc
402 @opindex nostdinc
403 Do not search the standard system directories for header files.
404 Only the directories you have specified with @option{-I} options
405 (and the directory of the current file, if appropriate) are searched.
406
407 @item -nostdinc++
408 @opindex nostdinc++
409 Do not search for header files in the C++-specific standard directories,
410 but do still search the other standard directories.  (This option is
411 used when building the C++ library.)
412
413 @item -include @var{file}
414 @opindex include
415 Process @var{file} as if @code{#include "file"} appeared as the first
416 line of the primary source file.  However, the first directory searched
417 for @var{file} is the preprocessor's working directory @emph{instead of}
418 the directory containing the main source file.  If not found there, it
419 is searched for in the remainder of the @code{#include "@dots{}"} search
420 chain as normal.
421
422 If multiple @option{-include} options are given, the files are included
423 in the order they appear on the command line.
424
425 @item -imacros @var{file}
426 @opindex imacros
427 Exactly like @option{-include}, except that any output produced by
428 scanning @var{file} is thrown away.  Macros it defines remain defined.
429 This allows you to acquire all the macros from a header without also
430 processing its declarations.
431
432 All files specified by @option{-imacros} are processed before all files
433 specified by @option{-include}.
434
435 @item -idirafter @var{dir}
436 @opindex idirafter
437 Search @var{dir} for header files, but do it @emph{after} all
438 directories specified with @option{-I} and the standard system directories
439 have been exhausted.  @var{dir} is treated as a system include directory.
440
441 @item -iprefix @var{prefix}
442 @opindex iprefix
443 Specify @var{prefix} as the prefix for subsequent @option{-iwithprefix}
444 options.  If the prefix represents a directory, you should include the
445 final @samp{/}.
446
447 @item -iwithprefix @var{dir}
448 @itemx -iwithprefixbefore @var{dir}
449 @opindex iwithprefix
450 @opindex iwithprefixbefore
451 Append @var{dir} to the prefix specified previously with
452 @option{-iprefix}, and add the resulting directory to the include search
453 path.  @option{-iwithprefixbefore} puts it in the same place @option{-I}
454 would; @option{-iwithprefix} puts it where @option{-idirafter} would.
455
456 Use of these options is discouraged.
457
458 @item -isystem @var{dir}
459 @opindex isystem
460 Search @var{dir} for header files, after all directories specified by
461 @option{-I} but before the standard system directories.  Mark it
462 as a system directory, so that it gets the same special treatment as
463 is applied to the standard system directories.
464 @ifset cppmanual
465 @xref{System Headers}.
466 @end ifset
467
468 @item -fpreprocessed
469 @opindex fpreprocessed
470 Indicate to the preprocessor that the input file has already been
471 preprocessed.  This suppresses things like macro expansion, trigraph
472 conversion, escaped newline splicing, and processing of most directives.
473 The preprocessor still recognizes and removes comments, so that you can
474 pass a file preprocessed with @option{-C} to the compiler without
475 problems.  In this mode the integrated preprocessor is little more than
476 a tokenizer for the front ends.
477
478 @option{-fpreprocessed} is implicit if the input file has one of the
479 extensions @samp{.i}, @samp{.ii} or @samp{.mi}.  These are the
480 extensions that GCC uses for preprocessed files created by
481 @option{-save-temps}.
482
483 @item -ftabstop=@var{width}
484 @opindex ftabstop
485 Set the distance between tab stops.  This helps the preprocessor report
486 correct column numbers in warnings or errors, even if tabs appear on the
487 line.  If the value is less than 1 or greater than 100, the option is
488 ignored.  The default is 8.
489
490 @item -fno-show-column
491 @opindex fno-show-column
492 Do not print column numbers in diagnostics.  This may be necessary if
493 diagnostics are being scanned by a program that does not understand the
494 column numbers, such as @command{dejagnu}.
495
496 @item -A @var{predicate}=@var{answer}
497 @opindex A
498 Make an assertion with the predicate @var{predicate} and answer
499 @var{answer}.  This form is preferred to the older form @option{-A
500 @var{predicate}(@var{answer})}, which is still supported, because
501 it does not use shell special characters.
502 @ifset cppmanual
503 @xref{Assertions}.
504 @end ifset
505
506 @item -A -@var{predicate}=@var{answer}
507 Cancel an assertion with the predicate @var{predicate} and answer
508 @var{answer}.
509
510 @item -dCHARS
511 @var{CHARS} is a sequence of one or more of the following characters,
512 and must not be preceded by a space.  Other characters are interpreted
513 by the compiler proper, or reserved for future versions of GCC, and so
514 are silently ignored.  If you specify characters whose behavior
515 conflicts, the result is undefined.
516
517 @table @samp
518 @item M
519 @opindex dM
520 Instead of the normal output, generate a list of @samp{#define}
521 directives for all the macros defined during the execution of the
522 preprocessor, including predefined macros.  This gives you a way of
523 finding out what is predefined in your version of the preprocessor.
524 Assuming you have no file @file{foo.h}, the command
525
526 @example
527 touch foo.h; cpp -dM foo.h
528 @end example
529
530 @noindent
531 will show all the predefined macros.
532
533 @item D
534 @opindex dD
535 Like @samp{M} except in two respects: it does @emph{not} include the
536 predefined macros, and it outputs @emph{both} the @samp{#define}
537 directives and the result of preprocessing.  Both kinds of output go to
538 the standard output file.
539
540 @item N
541 @opindex dN
542 Like @samp{D}, but emit only the macro names, not their expansions.
543
544 @item I
545 @opindex dI
546 Output @samp{#include} directives in addition to the result of
547 preprocessing.
548 @end table
549
550 @item -P
551 @opindex P
552 Inhibit generation of linemarkers in the output from the preprocessor.
553 This might be useful when running the preprocessor on something that is
554 not C code, and will be sent to a program which might be confused by the
555 linemarkers.
556 @ifset cppmanual
557 @xref{Preprocessor Output}.
558 @end ifset
559
560 @item -C
561 @opindex C
562 Do not discard comments.  All comments are passed through to the output
563 file, except for comments in processed directives, which are deleted
564 along with the directive.
565
566 You should be prepared for side effects when using @option{-C}; it
567 causes the preprocessor to treat comments as tokens in their own right.
568 For example, comments appearing at the start of what would be a
569 directive line have the effect of turning that line into an ordinary
570 source line, since the first token on the line is no longer a @samp{#}.
571
572 @item -CC
573 Do not discard comments, including during macro expansion.  This is
574 like @option{-C}, except that comments contained within macros are
575 also passed through to the output file where the macro is expanded.
576
577 In addition to the side-effects of the @option{-C} option, the
578 @option{-CC} option causes all C++-style comments inside a macro
579 to be converted to C-style comments.  This is to prevent later use
580 of that macro from inadvertently commenting out the remainder of
581 the source line.
582
583 The @option{-CC} option is generally used to support lint comments.
584
585 @item -gcc
586 @opindex gcc
587 Define the macros @sc{__gnuc__}, @sc{__gnuc_minor__} and
588 @sc{__gnuc_patchlevel__}.  These are defined automatically when you use
589 @command{gcc -E}; you can turn them off in that case with
590 @option{-no-gcc}.
591
592 @item -traditional-cpp
593 @opindex traditional-cpp
594 Try to imitate the behavior of old-fashioned C preprocessors, as
595 opposed to ISO C preprocessors.
596 @ifset cppmanual
597 @xref{Traditional Mode}.
598 @end ifset
599
600 @item -trigraphs
601 @opindex trigraphs
602 Process trigraph sequences.
603 @ifset cppmanual
604 @xref{Initial processing}.
605 @end ifset
606 @ifclear cppmanual
607 These are three-character sequences, all starting with @samp{??}, that
608 are defined by ISO C to stand for single characters.  For example,
609 @samp{??/} stands for @samp{\}, so @samp{'??/n'} is a character
610 constant for a newline.  By default, GCC ignores trigraphs, but in
611 standard-conforming modes it converts them.  See the @option{-std} and
612 @option{-ansi} options.
613
614 The nine trigraphs and their replacements are
615
616 @smallexample
617 Trigraph:       ??(  ??)  ??<  ??>  ??=  ??/  ??'  ??!  ??-
618 Replacement:      [    ]    @{    @}    #    \    ^    |    ~
619 @end smallexample
620 @end ifclear
621
622 @item -remap
623 @opindex remap
624 Enable special code to work around file systems which only permit very
625 short file names, such as MS-DOS@.
626
627 @itemx --help
628 @itemx --target-help
629 @opindex help
630 @opindex target-help
631 Print text describing all the command line options instead of
632 preprocessing anything.
633
634 @item -v
635 @opindex v
636 Verbose mode.  Print out GNU CPP's version number at the beginning of
637 execution, and report the final form of the include path.
638
639 @item -H
640 @opindex H
641 Print the name of each header file used, in addition to other normal
642 activities.  Each name is indented to show how deep in the
643 @samp{#include} stack it is.
644
645 @item -version
646 @itemx --version
647 @opindex version
648 Print out GNU CPP's version number.  With one dash, proceed to
649 preprocess as normal.  With two dashes, exit immediately.
650 @end table