1 @c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2 @c 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
3 @c This is part of the GCC manual.
4 @c For copying conditions, see the file gcc.texi.
8 Copyright @copyright{} 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
9 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
11 Permission is granted to copy, distribute and/or modify this document
12 under the terms of the GNU Free Documentation License, Version 1.2 or
13 any later version published by the Free Software Foundation; with the
14 Invariant Sections being ``GNU General Public License'' and ``Funding
15 Free Software'', the Front-Cover texts being (a) (see below), and with
16 the Back-Cover Texts being (b) (see below). A copy of the license is
17 included in the gfdl(7) man page.
19 (a) The FSF's Front-Cover Text is:
23 (b) The FSF's Back-Cover Text is:
25 You have freedom to copy and modify this GNU Manual, like GNU
26 software. Copies published by the Free Software Foundation raise
27 funds for GNU development.
29 @c Set file name and title for the man page.
31 @settitle GNU project C and C++ compiler
33 gcc [@option{-c}|@option{-S}|@option{-E}] [@option{-std=}@var{standard}]
34 [@option{-g}] [@option{-pg}] [@option{-O}@var{level}]
35 [@option{-W}@var{warn}@dots{}] [@option{-pedantic}]
36 [@option{-I}@var{dir}@dots{}] [@option{-L}@var{dir}@dots{}]
37 [@option{-D}@var{macro}[=@var{defn}]@dots{}] [@option{-U}@var{macro}]
38 [@option{-f}@var{option}@dots{}] [@option{-m}@var{machine-option}@dots{}]
39 [@option{-o} @var{outfile}] @var{infile}@dots{}
41 Only the most useful options are listed here; see below for the
42 remainder. @samp{g++} accepts mostly the same options as @samp{gcc}.
45 gpl(7), gfdl(7), fsf-funding(7),
46 cpp(1), gcov(1), as(1), ld(1), gdb(1), adb(1), dbx(1), sdb(1)
47 and the Info entries for @file{gcc}, @file{cpp}, @file{as},
48 @file{ld}, @file{binutils} and @file{gdb}.
51 For instructions on reporting bugs, see
52 @w{@uref{http://gcc.gnu.org/bugs.html}}.
55 See the Info entry for @command{gcc}, or
56 @w{@uref{http://gcc.gnu.org/onlinedocs/gcc/Contributors.html}},
57 for contributors to GCC@.
62 @chapter GCC Command Options
63 @cindex GCC command options
64 @cindex command options
65 @cindex options, GCC command
67 @c man begin DESCRIPTION
68 When you invoke GCC, it normally does preprocessing, compilation,
69 assembly and linking. The ``overall options'' allow you to stop this
70 process at an intermediate stage. For example, the @option{-c} option
71 says not to run the linker. Then the output consists of object files
72 output by the assembler.
74 Other options are passed on to one stage of processing. Some options
75 control the preprocessor and others the compiler itself. Yet other
76 options control the assembler and linker; most of these are not
77 documented here, since you rarely need to use any of them.
79 @cindex C compilation options
80 Most of the command line options that you can use with GCC are useful
81 for C programs; when an option is only useful with another language
82 (usually C++), the explanation says so explicitly. If the description
83 for a particular option does not mention a source language, you can use
84 that option with all supported languages.
86 @cindex C++ compilation options
87 @xref{Invoking G++,,Compiling C++ Programs}, for a summary of special
88 options for compiling C++ programs.
90 @cindex grouping options
91 @cindex options, grouping
92 The @command{gcc} program accepts options and file names as operands. Many
93 options have multi-letter names; therefore multiple single-letter options
94 may @emph{not} be grouped: @option{-dr} is very different from @w{@samp{-d
97 @cindex order of options
98 @cindex options, order
99 You can mix options and other arguments. For the most part, the order
100 you use doesn't matter. Order does matter when you use several options
101 of the same kind; for example, if you specify @option{-L} more than once,
102 the directories are searched in the order specified.
104 Many options have long names starting with @samp{-f} or with
105 @samp{-W}---for example,
106 @option{-fstrength-reduce}, @option{-Wformat} and so on. Most of
107 these have both positive and negative forms; the negative form of
108 @option{-ffoo} would be @option{-fno-foo}. This manual documents
109 only one of these two forms, whichever one is not the default.
113 @xref{Option Index}, for an index to GCC's options.
116 * Option Summary:: Brief list of all options, without explanations.
117 * Overall Options:: Controlling the kind of output:
118 an executable, object files, assembler files,
119 or preprocessed source.
120 * Invoking G++:: Compiling C++ programs.
121 * C Dialect Options:: Controlling the variant of C language compiled.
122 * C++ Dialect Options:: Variations on C++.
123 * Objective-C and Objective-C++ Dialect Options:: Variations on Objective-C
125 * Language Independent Options:: Controlling how diagnostics should be
127 * Warning Options:: How picky should the compiler be?
128 * Debugging Options:: Symbol tables, measurements, and debugging dumps.
129 * Optimize Options:: How much optimization?
130 * Preprocessor Options:: Controlling header files and macro definitions.
131 Also, getting dependency information for Make.
132 * Assembler Options:: Passing options to the assembler.
133 * Link Options:: Specifying libraries and so on.
134 * Directory Options:: Where to find header files and libraries.
135 Where to find the compiler executable files.
136 * Spec Files:: How to pass switches to sub-processes.
137 * Target Options:: Running a cross-compiler, or an old version of GCC.
138 * Submodel Options:: Specifying minor hardware or convention variations,
139 such as 68010 vs 68020.
140 * Code Gen Options:: Specifying conventions for function calls, data layout
142 * Environment Variables:: Env vars that affect GCC.
143 * Precompiled Headers:: Compiling a header once, and using it many times.
144 * Running Protoize:: Automatically adding or removing function prototypes.
150 @section Option Summary
152 Here is a summary of all the options, grouped by type. Explanations are
153 in the following sections.
156 @item Overall Options
157 @xref{Overall Options,,Options Controlling the Kind of Output}.
158 @gccoptlist{-c -S -E -o @var{file} -combine -pipe -pass-exit-codes @gol
159 -x @var{language} -v -### --help --target-help --version}
161 @item C Language Options
162 @xref{C Dialect Options,,Options Controlling C Dialect}.
163 @gccoptlist{-ansi -std=@var{standard} -aux-info @var{filename} @gol
164 -fno-asm -fno-builtin -fno-builtin-@var{function} @gol
165 -fhosted -ffreestanding -fms-extensions @gol
166 -trigraphs -no-integrated-cpp -traditional -traditional-cpp @gol
167 -fallow-single-precision -fcond-mismatch @gol
168 -fsigned-bitfields -fsigned-char @gol
169 -funsigned-bitfields -funsigned-char}
171 @item C++ Language Options
172 @xref{C++ Dialect Options,,Options Controlling C++ Dialect}.
173 @gccoptlist{-fabi-version=@var{n} -fno-access-control -fcheck-new @gol
174 -fconserve-space -fno-const-strings @gol
175 -fno-elide-constructors @gol
176 -fno-enforce-eh-specs @gol
177 -ffor-scope -fno-for-scope -fno-gnu-keywords @gol
178 -fno-implicit-templates @gol
179 -fno-implicit-inline-templates @gol
180 -fno-implement-inlines -fms-extensions @gol
181 -fno-nonansi-builtins -fno-operator-names @gol
182 -fno-optional-diags -fpermissive @gol
183 -frepo -fno-rtti -fstats -ftemplate-depth-@var{n} @gol
184 -fno-threadsafe-statics -fuse-cxa-atexit -fno-weak -nostdinc++ @gol
185 -fno-default-inline -fvisibility-inlines-hidden @gol
186 -Wabi -Wctor-dtor-privacy @gol
187 -Wnon-virtual-dtor -Wreorder @gol
188 -Weffc++ -Wno-deprecated -Wstrict-null-sentinel @gol
189 -Wno-non-template-friend -Wold-style-cast @gol
190 -Woverloaded-virtual -Wno-pmf-conversions @gol
193 @item Objective-C and Objective-C++ Language Options
194 @xref{Objective-C and Objective-C++ Dialect Options,,Options Controlling
195 Objective-C and Objective-C++ Dialects}.
197 -fconstant-string-class=@var{class-name} @gol
198 -fgnu-runtime -fnext-runtime @gol
199 -fno-nil-receivers @gol
200 -fobjc-call-cxx-cdtors @gol
201 -fobjc-direct-dispatch @gol
202 -fobjc-exceptions @gol
204 -freplace-objc-classes @gol
207 -Wassign-intercept @gol
208 -Wno-protocol -Wselector @gol
209 -Wstrict-selector-match @gol
210 -Wundeclared-selector}
212 @item Language Independent Options
213 @xref{Language Independent Options,,Options to Control Diagnostic Messages Formatting}.
214 @gccoptlist{-fmessage-length=@var{n} @gol
215 -fdiagnostics-show-location=@r{[}once@r{|}every-line@r{]}} @gol
216 -fdiagnostics-show-options
218 @item Warning Options
219 @xref{Warning Options,,Options to Request or Suppress Warnings}.
220 @gccoptlist{-fsyntax-only -pedantic -pedantic-errors @gol
221 -w -Wextra -Wall -Waggregate-return -Wno-attributes @gol
222 -Wc++-compat -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment @gol
223 -Wconversion -Wno-deprecated-declarations @gol
224 -Wdisabled-optimization -Wno-div-by-zero -Wno-endif-labels @gol
225 -Werror -Werror-implicit-function-declaration @gol
226 -Wfatal-errors -Wfloat-equal -Wformat -Wformat=2 @gol
227 -Wno-format-extra-args -Wformat-nonliteral @gol
228 -Wformat-security -Wformat-y2k @gol
229 -Wimplicit -Wimplicit-function-declaration -Wimplicit-int @gol
230 -Wimport -Wno-import -Winit-self -Winline @gol
231 -Wno-int-to-pointer-cast @gol
232 -Wno-invalid-offsetof -Winvalid-pch @gol
233 -Wlarger-than-@var{len} -Wunsafe-loop-optimizations -Wlong-long @gol
234 -Wmain -Wmissing-braces -Wmissing-field-initializers @gol
235 -Wmissing-format-attribute -Wmissing-include-dirs @gol
236 -Wmissing-noreturn @gol
237 -Wno-multichar -Wnonnull -Wpacked -Wpadded @gol
238 -Wparentheses -Wpointer-arith -Wno-pointer-to-int-cast @gol
239 -Wredundant-decls @gol
240 -Wreturn-type -Wsequence-point -Wshadow @gol
241 -Wsign-compare -Wstrict-aliasing -Wstrict-aliasing=2 @gol
242 -Wswitch -Wswitch-default -Wswitch-enum @gol
243 -Wsystem-headers -Wtrigraphs -Wundef -Wuninitialized @gol
244 -Wunknown-pragmas -Wno-pragmas -Wunreachable-code @gol
245 -Wunused -Wunused-function -Wunused-label -Wunused-parameter @gol
246 -Wunused-value -Wunused-variable -Wwrite-strings @gol
249 @item C-only Warning Options
250 @gccoptlist{-Wbad-function-cast -Wmissing-declarations @gol
251 -Wmissing-prototypes -Wnested-externs -Wold-style-definition @gol
252 -Wstrict-prototypes -Wtraditional @gol
253 -Wdeclaration-after-statement -Wno-pointer-sign}
255 @item Debugging Options
256 @xref{Debugging Options,,Options for Debugging Your Program or GCC}.
257 @gccoptlist{-d@var{letters} -dumpspecs -dumpmachine -dumpversion @gol
258 -fdump-unnumbered -fdump-translation-unit@r{[}-@var{n}@r{]} @gol
259 -fdump-class-hierarchy@r{[}-@var{n}@r{]} @gol
260 -fdump-ipa-all -fdump-ipa-cgraph @gol
262 -fdump-tree-original@r{[}-@var{n}@r{]} @gol
263 -fdump-tree-optimized@r{[}-@var{n}@r{]} @gol
264 -fdump-tree-inlined@r{[}-@var{n}@r{]} @gol
265 -fdump-tree-cfg -fdump-tree-vcg -fdump-tree-alias @gol
267 -fdump-tree-ssa@r{[}-@var{n}@r{]} -fdump-tree-pre@r{[}-@var{n}@r{]} @gol
268 -fdump-tree-ccp@r{[}-@var{n}@r{]} -fdump-tree-dce@r{[}-@var{n}@r{]} @gol
269 -fdump-tree-gimple@r{[}-raw@r{]} -fdump-tree-mudflap@r{[}-@var{n}@r{]} @gol
270 -fdump-tree-dom@r{[}-@var{n}@r{]} @gol
271 -fdump-tree-dse@r{[}-@var{n}@r{]} @gol
272 -fdump-tree-phiopt@r{[}-@var{n}@r{]} @gol
273 -fdump-tree-forwprop@r{[}-@var{n}@r{]} @gol
274 -fdump-tree-copyrename@r{[}-@var{n}@r{]} @gol
275 -fdump-tree-nrv -fdump-tree-vect @gol
276 -fdump-tree-sink @gol
277 -fdump-tree-sra@r{[}-@var{n}@r{]} @gol
278 -fdump-tree-salias @gol
279 -fdump-tree-fre@r{[}-@var{n}@r{]} @gol
280 -fdump-tree-vrp@r{[}-@var{n}@r{]} @gol
281 -ftree-vectorizer-verbose=@var{n} @gol
282 -fdump-tree-storeccp@r{[}-@var{n}@r{]} @gol
283 -feliminate-dwarf2-dups -feliminate-unused-debug-types @gol
284 -feliminate-unused-debug-symbols -fmem-report -fprofile-arcs @gol
285 -frandom-seed=@var{string} -fsched-verbose=@var{n} @gol
286 -ftest-coverage -ftime-report -fvar-tracking @gol
287 -g -g@var{level} -gcoff -gdwarf-2 @gol
288 -ggdb -gstabs -gstabs+ -gvms -gxcoff -gxcoff+ @gol
289 -p -pg -print-file-name=@var{library} -print-libgcc-file-name @gol
290 -print-multi-directory -print-multi-lib @gol
291 -print-prog-name=@var{program} -print-search-dirs -Q @gol
294 @item Optimization Options
295 @xref{Optimize Options,,Options that Control Optimization}.
296 @gccoptlist{-falign-functions=@var{n} -falign-jumps=@var{n} @gol
297 -falign-labels=@var{n} -falign-loops=@var{n} @gol
298 -fbounds-check -fmudflap -fmudflapth -fmudflapir @gol
299 -fbranch-probabilities -fprofile-values -fvpt -fbranch-target-load-optimize @gol
300 -fbranch-target-load-optimize2 -fbtr-bb-exclusive @gol
301 -fcaller-saves -fcprop-registers -fcse-follow-jumps @gol
302 -fcse-skip-blocks -fcx-limited-range -fdata-sections @gol
303 -fdelayed-branch -fdelete-null-pointer-checks -fearly-inlining @gol
304 -fexpensive-optimizations -ffast-math -ffloat-store @gol
305 -fforce-addr -ffunction-sections @gol
306 -fgcse -fgcse-lm -fgcse-sm -fgcse-las -fgcse-after-reload @gol
307 -floop-optimize -fcrossjumping -fif-conversion -fif-conversion2 @gol
308 -finline-functions -finline-limit=@var{n} -fkeep-inline-functions @gol
309 -fkeep-static-consts -fmerge-constants -fmerge-all-constants @gol
310 -fmodulo-sched -fno-branch-count-reg @gol
311 -fno-default-inline -fno-defer-pop -floop-optimize2 -fmove-loop-invariants @gol
312 -fno-function-cse -fno-guess-branch-probability @gol
313 -fno-inline -fno-math-errno -fno-peephole -fno-peephole2 @gol
314 -funsafe-math-optimizations -funsafe-loop-optimizations -ffinite-math-only @gol
315 -fno-trapping-math -fno-zero-initialized-in-bss @gol
316 -fomit-frame-pointer -foptimize-register-move @gol
317 -foptimize-sibling-calls -fprefetch-loop-arrays @gol
318 -fprofile-generate -fprofile-use @gol
319 -fregmove -frename-registers @gol
320 -freorder-blocks -freorder-blocks-and-partition -freorder-functions @gol
321 -frerun-cse-after-loop -frerun-loop-opt @gol
322 -frounding-math -fschedule-insns -fschedule-insns2 @gol
323 -fno-sched-interblock -fno-sched-spec -fsched-spec-load @gol
324 -fsched-spec-load-dangerous @gol
325 -fsched-stalled-insns=@var{n} -sched-stalled-insns-dep=@var{n} @gol
326 -fsched2-use-superblocks @gol
327 -fsched2-use-traces -freschedule-modulo-scheduled-loops @gol
328 -fsignaling-nans -fsingle-precision-constant @gol
329 -fstrength-reduce -fstrict-aliasing -ftracer -fthread-jumps @gol
330 -funroll-all-loops -funroll-loops -fpeel-loops @gol
331 -fsplit-ivs-in-unroller -funswitch-loops @gol
332 -fvariable-expansion-in-unroller @gol
333 -ftree-pre -ftree-ccp -ftree-dce -ftree-loop-optimize @gol
334 -ftree-loop-linear -ftree-loop-im -ftree-loop-ivcanon -fivopts @gol
335 -ftree-dominator-opts -ftree-dse -ftree-copyrename -ftree-sink @gol
336 -ftree-ch -ftree-sra -ftree-ter -ftree-lrs -ftree-fre -ftree-vectorize @gol
337 -ftree-salias -fweb @gol
338 -ftree-copy-prop -ftree-store-ccp -ftree-store-copy-prop -fwhole-program @gol
339 --param @var{name}=@var{value}
340 -O -O0 -O1 -O2 -O3 -Os}
342 @item Preprocessor Options
343 @xref{Preprocessor Options,,Options Controlling the Preprocessor}.
344 @gccoptlist{-A@var{question}=@var{answer} @gol
345 -A-@var{question}@r{[}=@var{answer}@r{]} @gol
346 -C -dD -dI -dM -dN @gol
347 -D@var{macro}@r{[}=@var{defn}@r{]} -E -H @gol
348 -idirafter @var{dir} @gol
349 -include @var{file} -imacros @var{file} @gol
350 -iprefix @var{file} -iwithprefix @var{dir} @gol
351 -iwithprefixbefore @var{dir} -isystem @var{dir} @gol
352 -isysroot @var{dir} @gol
353 -M -MM -MF -MG -MP -MQ -MT -nostdinc @gol
354 -P -fworking-directory -remap @gol
355 -trigraphs -undef -U@var{macro} -Wp,@var{option} @gol
356 -Xpreprocessor @var{option}}
358 @item Assembler Option
359 @xref{Assembler Options,,Passing Options to the Assembler}.
360 @gccoptlist{-Wa,@var{option} -Xassembler @var{option}}
363 @xref{Link Options,,Options for Linking}.
364 @gccoptlist{@var{object-file-name} -l@var{library} @gol
365 -nostartfiles -nodefaultlibs -nostdlib -pie @gol
366 -s -static -static-libgcc -shared -shared-libgcc -symbolic @gol
367 -Wl,@var{option} -Xlinker @var{option} @gol
370 @item Directory Options
371 @xref{Directory Options,,Options for Directory Search}.
372 @gccoptlist{-B@var{prefix} -I@var{dir} -iquote@var{dir} -L@var{dir}
373 -specs=@var{file} -I- --sysroot=@var{dir}}
376 @c I wrote this xref this way to avoid overfull hbox. -- rms
377 @xref{Target Options}.
378 @gccoptlist{-V @var{version} -b @var{machine}}
380 @item Machine Dependent Options
381 @xref{Submodel Options,,Hardware Models and Configurations}.
382 @c This list is ordered alphanumerically by subsection name.
383 @c Try and put the significant identifier (CPU or system) first,
384 @c so users have a clue at guessing where the ones they want will be.
387 @gccoptlist{-EB -EL @gol
388 -mmangle-cpu -mcpu=@var{cpu} -mtext=@var{text-section} @gol
389 -mdata=@var{data-section} -mrodata=@var{readonly-data-section}}
392 @gccoptlist{-mapcs-frame -mno-apcs-frame @gol
393 -mabi=@var{name} @gol
394 -mapcs-stack-check -mno-apcs-stack-check @gol
395 -mapcs-float -mno-apcs-float @gol
396 -mapcs-reentrant -mno-apcs-reentrant @gol
397 -msched-prolog -mno-sched-prolog @gol
398 -mlittle-endian -mbig-endian -mwords-little-endian @gol
399 -mfloat-abi=@var{name} -msoft-float -mhard-float -mfpe @gol
400 -mthumb-interwork -mno-thumb-interwork @gol
401 -mcpu=@var{name} -march=@var{name} -mfpu=@var{name} @gol
402 -mstructure-size-boundary=@var{n} @gol
403 -mabort-on-noreturn @gol
404 -mlong-calls -mno-long-calls @gol
405 -msingle-pic-base -mno-single-pic-base @gol
406 -mpic-register=@var{reg} @gol
407 -mnop-fun-dllimport @gol
408 -mcirrus-fix-invalid-insns -mno-cirrus-fix-invalid-insns @gol
409 -mpoke-function-name @gol
411 -mtpcs-frame -mtpcs-leaf-frame @gol
412 -mcaller-super-interworking -mcallee-super-interworking}
415 @gccoptlist{-mmcu=@var{mcu} -msize -minit-stack=@var{n} -mno-interrupts @gol
416 -mcall-prologues -mno-tablejump -mtiny-stack -mint8}
418 @emph{Blackfin Options}
419 @gccoptlist{-momit-leaf-frame-pointer -mno-omit-leaf-frame-pointer @gol
420 -mspecld-anomaly -mno-specld-anomaly -mcsync-anomaly -mno-csync-anomaly @gol
421 -mlow-64k -mno-low64k -mid-shared-library @gol
422 -mno-id-shared-library -mshared-library-id=@var{n} @gol
423 -mlong-calls -mno-long-calls}
426 @gccoptlist{-mcpu=@var{cpu} -march=@var{cpu} -mtune=@var{cpu} @gol
427 -mmax-stack-frame=@var{n} -melinux-stacksize=@var{n} @gol
428 -metrax4 -metrax100 -mpdebug -mcc-init -mno-side-effects @gol
429 -mstack-align -mdata-align -mconst-align @gol
430 -m32-bit -m16-bit -m8-bit -mno-prologue-epilogue -mno-gotplt @gol
431 -melf -maout -melinux -mlinux -sim -sim2 @gol
432 -mmul-bug-workaround -mno-mul-bug-workaround}
434 @emph{Darwin Options}
435 @gccoptlist{-all_load -allowable_client -arch -arch_errors_fatal @gol
436 -arch_only -bind_at_load -bundle -bundle_loader @gol
437 -client_name -compatibility_version -current_version @gol
439 -dependency-file -dylib_file -dylinker_install_name @gol
440 -dynamic -dynamiclib -exported_symbols_list @gol
441 -filelist -flat_namespace -force_cpusubtype_ALL @gol
442 -force_flat_namespace -headerpad_max_install_names @gol
443 -image_base -init -install_name -keep_private_externs @gol
444 -multi_module -multiply_defined -multiply_defined_unused @gol
445 -noall_load -no_dead_strip_inits_and_terms @gol
446 -nofixprebinding -nomultidefs -noprebind -noseglinkedit @gol
447 -pagezero_size -prebind -prebind_all_twolevel_modules @gol
448 -private_bundle -read_only_relocs -sectalign @gol
449 -sectobjectsymbols -whyload -seg1addr @gol
450 -sectcreate -sectobjectsymbols -sectorder @gol
451 -segaddr -segs_read_only_addr -segs_read_write_addr @gol
452 -seg_addr_table -seg_addr_table_filename -seglinkedit @gol
453 -segprot -segs_read_only_addr -segs_read_write_addr @gol
454 -single_module -static -sub_library -sub_umbrella @gol
455 -twolevel_namespace -umbrella -undefined @gol
456 -unexported_symbols_list -weak_reference_mismatches @gol
457 -whatsloaded -F -gused -gfull -mmacosx-min-version=@var{version} @gol
460 @emph{DEC Alpha Options}
461 @gccoptlist{-mno-fp-regs -msoft-float -malpha-as -mgas @gol
462 -mieee -mieee-with-inexact -mieee-conformant @gol
463 -mfp-trap-mode=@var{mode} -mfp-rounding-mode=@var{mode} @gol
464 -mtrap-precision=@var{mode} -mbuild-constants @gol
465 -mcpu=@var{cpu-type} -mtune=@var{cpu-type} @gol
466 -mbwx -mmax -mfix -mcix @gol
467 -mfloat-vax -mfloat-ieee @gol
468 -mexplicit-relocs -msmall-data -mlarge-data @gol
469 -msmall-text -mlarge-text @gol
470 -mmemory-latency=@var{time}}
472 @emph{DEC Alpha/VMS Options}
473 @gccoptlist{-mvms-return-codes}
476 @gccoptlist{-mgpr-32 -mgpr-64 -mfpr-32 -mfpr-64 @gol
477 -mhard-float -msoft-float @gol
478 -malloc-cc -mfixed-cc -mdword -mno-dword @gol
479 -mdouble -mno-double @gol
480 -mmedia -mno-media -mmuladd -mno-muladd @gol
481 -mfdpic -minline-plt -mgprel-ro -multilib-library-pic @gol
482 -mlinked-fp -mlong-calls -malign-labels @gol
483 -mlibrary-pic -macc-4 -macc-8 @gol
484 -mpack -mno-pack -mno-eflags -mcond-move -mno-cond-move @gol
485 -moptimize-membar -mno-optimize-membar @gol
486 -mscc -mno-scc -mcond-exec -mno-cond-exec @gol
487 -mvliw-branch -mno-vliw-branch @gol
488 -mmulti-cond-exec -mno-multi-cond-exec -mnested-cond-exec @gol
489 -mno-nested-cond-exec -mtomcat-stats @gol
493 @emph{H8/300 Options}
494 @gccoptlist{-mrelax -mh -ms -mn -mint32 -malign-300}
497 @gccoptlist{-march=@var{architecture-type} @gol
498 -mbig-switch -mdisable-fpregs -mdisable-indexing @gol
499 -mfast-indirect-calls -mgas -mgnu-ld -mhp-ld @gol
500 -mfixed-range=@var{register-range} @gol
501 -mjump-in-delay -mlinker-opt -mlong-calls @gol
502 -mlong-load-store -mno-big-switch -mno-disable-fpregs @gol
503 -mno-disable-indexing -mno-fast-indirect-calls -mno-gas @gol
504 -mno-jump-in-delay -mno-long-load-store @gol
505 -mno-portable-runtime -mno-soft-float @gol
506 -mno-space-regs -msoft-float -mpa-risc-1-0 @gol
507 -mpa-risc-1-1 -mpa-risc-2-0 -mportable-runtime @gol
508 -mschedule=@var{cpu-type} -mspace-regs -msio -mwsio @gol
509 -munix=@var{unix-std} -nolibdld -static -threads}
511 @emph{i386 and x86-64 Options}
512 @gccoptlist{-mtune=@var{cpu-type} -march=@var{cpu-type} @gol
513 -mfpmath=@var{unit} @gol
514 -masm=@var{dialect} -mno-fancy-math-387 @gol
515 -mno-fp-ret-in-387 -msoft-float -msvr3-shlib @gol
516 -mno-wide-multiply -mrtd -malign-double @gol
517 -mpreferred-stack-boundary=@var{num} @gol
518 -mmmx -msse -msse2 -msse3 -m3dnow @gol
519 -mthreads -mno-align-stringops -minline-all-stringops @gol
520 -mpush-args -maccumulate-outgoing-args -m128bit-long-double @gol
521 -m96bit-long-double -mregparm=@var{num} -msseregparm @gol
522 -momit-leaf-frame-pointer -mno-red-zone -mno-tls-direct-seg-refs @gol
523 -mcmodel=@var{code-model} @gol
527 @gccoptlist{-mbig-endian -mlittle-endian -mgnu-as -mgnu-ld -mno-pic @gol
528 -mvolatile-asm-stop -mregister-names -mno-sdata @gol
529 -mconstant-gp -mauto-pic -minline-float-divide-min-latency @gol
530 -minline-float-divide-max-throughput @gol
531 -minline-int-divide-min-latency @gol
532 -minline-int-divide-max-throughput @gol
533 -minline-sqrt-min-latency -minline-sqrt-max-throughput @gol
534 -mno-dwarf2-asm -mearly-stop-bits @gol
535 -mfixed-range=@var{register-range} -mtls-size=@var{tls-size} @gol
536 -mtune=@var{cpu-type} -mt -pthread -milp32 -mlp64}
538 @emph{M32R/D Options}
539 @gccoptlist{-m32r2 -m32rx -m32r @gol
541 -malign-loops -mno-align-loops @gol
542 -missue-rate=@var{number} @gol
543 -mbranch-cost=@var{number} @gol
544 -mmodel=@var{code-size-model-type} @gol
545 -msdata=@var{sdata-type} @gol
546 -mno-flush-func -mflush-func=@var{name} @gol
547 -mno-flush-trap -mflush-trap=@var{number} @gol
551 @gccoptlist{-mcpu=@var{cpu} -msim -memregs=@var{number}}
553 @emph{M680x0 Options}
554 @gccoptlist{-m68000 -m68020 -m68020-40 -m68020-60 -m68030 -m68040 @gol
555 -m68060 -mcpu32 -m5200 -m68881 -mbitfield -mc68000 -mc68020 @gol
556 -mnobitfield -mrtd -mshort -msoft-float -mpcrel @gol
557 -malign-int -mstrict-align -msep-data -mno-sep-data @gol
558 -mshared-library-id=n -mid-shared-library -mno-id-shared-library}
560 @emph{M68hc1x Options}
561 @gccoptlist{-m6811 -m6812 -m68hc11 -m68hc12 -m68hcs12 @gol
562 -mauto-incdec -minmax -mlong-calls -mshort @gol
563 -msoft-reg-count=@var{count}}
566 @gccoptlist{-mhardlit -mno-hardlit -mdiv -mno-div -mrelax-immediates @gol
567 -mno-relax-immediates -mwide-bitfields -mno-wide-bitfields @gol
568 -m4byte-functions -mno-4byte-functions -mcallgraph-data @gol
569 -mno-callgraph-data -mslow-bytes -mno-slow-bytes -mno-lsim @gol
570 -mlittle-endian -mbig-endian -m210 -m340 -mstack-increment}
573 @gccoptlist{-EL -EB -march=@var{arch} -mtune=@var{arch} @gol
574 -mips1 -mips2 -mips3 -mips4 -mips32 -mips32r2 -mips64 @gol
575 -mips16 -mno-mips16 -mabi=@var{abi} -mabicalls -mno-abicalls @gol
576 -mxgot -mno-xgot -mgp32 -mgp64 -mfp32 -mfp64 @gol
577 -mhard-float -msoft-float -msingle-float -mdouble-float @gol
578 -mdsp -mpaired-single -mips3d @gol
579 -mlong64 -mlong32 -msym32 -mno-sym32 @gol
580 -G@var{num} -membedded-data -mno-embedded-data @gol
581 -muninit-const-in-rodata -mno-uninit-const-in-rodata @gol
582 -msplit-addresses -mno-split-addresses @gol
583 -mexplicit-relocs -mno-explicit-relocs @gol
584 -mcheck-zero-division -mno-check-zero-division @gol
585 -mdivide-traps -mdivide-breaks @gol
586 -mmemcpy -mno-memcpy -mlong-calls -mno-long-calls @gol
587 -mmad -mno-mad -mfused-madd -mno-fused-madd -nocpp @gol
588 -mfix-r4000 -mno-fix-r4000 -mfix-r4400 -mno-fix-r4400 @gol
589 -mfix-vr4120 -mno-fix-vr4120 -mfix-vr4130 @gol
590 -mfix-sb1 -mno-fix-sb1 @gol
591 -mflush-func=@var{func} -mno-flush-func @gol
592 -mbranch-likely -mno-branch-likely @gol
593 -mfp-exceptions -mno-fp-exceptions @gol
594 -mvr4130-align -mno-vr4130-align}
597 @gccoptlist{-mlibfuncs -mno-libfuncs -mepsilon -mno-epsilon -mabi=gnu @gol
598 -mabi=mmixware -mzero-extend -mknuthdiv -mtoplevel-symbols @gol
599 -melf -mbranch-predict -mno-branch-predict -mbase-addresses @gol
600 -mno-base-addresses -msingle-exit -mno-single-exit}
602 @emph{MN10300 Options}
603 @gccoptlist{-mmult-bug -mno-mult-bug @gol
604 -mam33 -mno-am33 @gol
605 -mam33-2 -mno-am33-2 @gol
608 @emph{PDP-11 Options}
609 @gccoptlist{-mfpu -msoft-float -mac0 -mno-ac0 -m40 -m45 -m10 @gol
610 -mbcopy -mbcopy-builtin -mint32 -mno-int16 @gol
611 -mint16 -mno-int32 -mfloat32 -mno-float64 @gol
612 -mfloat64 -mno-float32 -mabshi -mno-abshi @gol
613 -mbranch-expensive -mbranch-cheap @gol
614 -msplit -mno-split -munix-asm -mdec-asm}
616 @emph{PowerPC Options}
617 See RS/6000 and PowerPC Options.
619 @emph{RS/6000 and PowerPC Options}
620 @gccoptlist{-mcpu=@var{cpu-type} @gol
621 -mtune=@var{cpu-type} @gol
622 -mpower -mno-power -mpower2 -mno-power2 @gol
623 -mpowerpc -mpowerpc64 -mno-powerpc @gol
624 -maltivec -mno-altivec @gol
625 -mpowerpc-gpopt -mno-powerpc-gpopt @gol
626 -mpowerpc-gfxopt -mno-powerpc-gfxopt @gol
627 -mnew-mnemonics -mold-mnemonics @gol
628 -mfull-toc -mminimal-toc -mno-fp-in-toc -mno-sum-in-toc @gol
629 -m64 -m32 -mxl-compat -mno-xl-compat -mpe @gol
630 -malign-power -malign-natural @gol
631 -msoft-float -mhard-float -mmultiple -mno-multiple @gol
632 -mstring -mno-string -mupdate -mno-update @gol
633 -mfused-madd -mno-fused-madd -mbit-align -mno-bit-align @gol
634 -mstrict-align -mno-strict-align -mrelocatable @gol
635 -mno-relocatable -mrelocatable-lib -mno-relocatable-lib @gol
636 -mtoc -mno-toc -mlittle -mlittle-endian -mbig -mbig-endian @gol
637 -mdynamic-no-pic -maltivec -mswdiv @gol
638 -mprioritize-restricted-insns=@var{priority} @gol
639 -msched-costly-dep=@var{dependence_type} @gol
640 -minsert-sched-nops=@var{scheme} @gol
641 -mcall-sysv -mcall-netbsd @gol
642 -maix-struct-return -msvr4-struct-return @gol
643 -mabi=@var{abi-type} -msecure-plt -mbss-plt @gol
644 -misel -mno-isel @gol
645 -misel=yes -misel=no @gol
647 -mspe=yes -mspe=no @gol
648 -mvrsave -mno-vrsave @gol
649 -mfloat-gprs=yes -mfloat-gprs=no -mfloat-gprs=single -mfloat-gprs=double @gol
650 -mprototype -mno-prototype @gol
651 -msim -mmvme -mads -myellowknife -memb -msdata @gol
652 -msdata=@var{opt} -mvxworks -mwindiss -G @var{num} -pthread}
654 @emph{S/390 and zSeries Options}
655 @gccoptlist{-mtune=@var{cpu-type} -march=@var{cpu-type} @gol
656 -mhard-float -msoft-float -mbackchain -mno-backchain @gol
657 -mpacked-stack -mno-packed-stack @gol
658 -msmall-exec -mno-small-exec -mmvcle -mno-mvcle @gol
659 -m64 -m31 -mdebug -mno-debug -mesa -mzarch @gol
660 -mtpf-trace -mno-tpf-trace -mfused-madd -mno-fused-madd @gol
661 -mwarn-framesize -mwarn-dynamicstack -mstack-size -mstack-guard}
664 @gccoptlist{-m1 -m2 -m2e -m3 -m3e @gol
665 -m4-nofpu -m4-single-only -m4-single -m4 @gol
666 -m4a-nofpu -m4a-single-only -m4a-single -m4a -m4al @gol
667 -m5-64media -m5-64media-nofpu @gol
668 -m5-32media -m5-32media-nofpu @gol
669 -m5-compact -m5-compact-nofpu @gol
670 -mb -ml -mdalign -mrelax @gol
671 -mbigtable -mfmovd -mhitachi -mrenesas -mno-renesas -mnomacsave @gol
672 -mieee -misize -mpadstruct -mspace @gol
673 -mprefergot -musermode -multcost=@var{number} -mdiv=@var{strategy} @gol
674 -mdivsi3_libfunc=@var{name} @gol
675 -madjust-unroll -mindexed-addressing -mgettrcost=@var{number} -mpt-fixed @gol
679 @gccoptlist{-mcpu=@var{cpu-type} @gol
680 -mtune=@var{cpu-type} @gol
681 -mcmodel=@var{code-model} @gol
682 -m32 -m64 -mapp-regs -mno-app-regs @gol
683 -mfaster-structs -mno-faster-structs @gol
684 -mfpu -mno-fpu -mhard-float -msoft-float @gol
685 -mhard-quad-float -msoft-quad-float @gol
686 -mimpure-text -mno-impure-text -mlittle-endian @gol
687 -mstack-bias -mno-stack-bias @gol
688 -munaligned-doubles -mno-unaligned-doubles @gol
689 -mv8plus -mno-v8plus -mvis -mno-vis
692 @emph{System V Options}
693 @gccoptlist{-Qy -Qn -YP,@var{paths} -Ym,@var{dir}}
695 @emph{TMS320C3x/C4x Options}
696 @gccoptlist{-mcpu=@var{cpu} -mbig -msmall -mregparm -mmemparm @gol
697 -mfast-fix -mmpyi -mbk -mti -mdp-isr-reload @gol
698 -mrpts=@var{count} -mrptb -mdb -mloop-unsigned @gol
699 -mparallel-insns -mparallel-mpy -mpreserve-float}
702 @gccoptlist{-mlong-calls -mno-long-calls -mep -mno-ep @gol
703 -mprolog-function -mno-prolog-function -mspace @gol
704 -mtda=@var{n} -msda=@var{n} -mzda=@var{n} @gol
705 -mapp-regs -mno-app-regs @gol
706 -mdisable-callt -mno-disable-callt @gol
712 @gccoptlist{-mg -mgnu -munix}
714 @emph{x86-64 Options}
715 See i386 and x86-64 Options.
717 @emph{Xstormy16 Options}
720 @emph{Xtensa Options}
721 @gccoptlist{-mconst16 -mno-const16 @gol
722 -mfused-madd -mno-fused-madd @gol
723 -mtext-section-literals -mno-text-section-literals @gol
724 -mtarget-align -mno-target-align @gol
725 -mlongcalls -mno-longcalls}
727 @emph{zSeries Options}
728 See S/390 and zSeries Options.
730 @item Code Generation Options
731 @xref{Code Gen Options,,Options for Code Generation Conventions}.
732 @gccoptlist{-fcall-saved-@var{reg} -fcall-used-@var{reg} @gol
733 -ffixed-@var{reg} -fexceptions @gol
734 -fnon-call-exceptions -funwind-tables @gol
735 -fasynchronous-unwind-tables @gol
736 -finhibit-size-directive -finstrument-functions @gol
737 -fno-common -fno-ident @gol
738 -fpcc-struct-return -fpic -fPIC -fpie -fPIE @gol
739 -fno-jump-tables @gol
740 -freg-struct-return -fshared-data -fshort-enums @gol
741 -fshort-double -fshort-wchar @gol
742 -fverbose-asm -fpack-struct[=@var{n}] -fstack-check @gol
743 -fstack-limit-register=@var{reg} -fstack-limit-symbol=@var{sym} @gol
744 -fargument-alias -fargument-noalias @gol
745 -fargument-noalias-global -fleading-underscore @gol
746 -ftls-model=@var{model} @gol
747 -ftrapv -fwrapv -fbounds-check @gol
752 * Overall Options:: Controlling the kind of output:
753 an executable, object files, assembler files,
754 or preprocessed source.
755 * C Dialect Options:: Controlling the variant of C language compiled.
756 * C++ Dialect Options:: Variations on C++.
757 * Objective-C and Objective-C++ Dialect Options:: Variations on Objective-C
759 * Language Independent Options:: Controlling how diagnostics should be
761 * Warning Options:: How picky should the compiler be?
762 * Debugging Options:: Symbol tables, measurements, and debugging dumps.
763 * Optimize Options:: How much optimization?
764 * Preprocessor Options:: Controlling header files and macro definitions.
765 Also, getting dependency information for Make.
766 * Assembler Options:: Passing options to the assembler.
767 * Link Options:: Specifying libraries and so on.
768 * Directory Options:: Where to find header files and libraries.
769 Where to find the compiler executable files.
770 * Spec Files:: How to pass switches to sub-processes.
771 * Target Options:: Running a cross-compiler, or an old version of GCC.
774 @node Overall Options
775 @section Options Controlling the Kind of Output
777 Compilation can involve up to four stages: preprocessing, compilation
778 proper, assembly and linking, always in that order. GCC is capable of
779 preprocessing and compiling several files either into several
780 assembler input files, or into one assembler input file; then each
781 assembler input file produces an object file, and linking combines all
782 the object files (those newly compiled, and those specified as input)
783 into an executable file.
785 @cindex file name suffix
786 For any given input file, the file name suffix determines what kind of
791 C source code which must be preprocessed.
794 C source code which should not be preprocessed.
797 C++ source code which should not be preprocessed.
800 Objective-C source code. Note that you must link with the @file{libobjc}
801 library to make an Objective-C program work.
804 Objective-C source code which should not be preprocessed.
808 Objective-C++ source code. Note that you must link with the @file{libobjc}
809 library to make an Objective-C++ program work. Note that @samp{.M} refers
810 to a literal capital M@.
813 Objective-C++ source code which should not be preprocessed.
816 C, C++, Objective-C or Objective-C++ header file to be turned into a
821 @itemx @var{file}.cxx
822 @itemx @var{file}.cpp
823 @itemx @var{file}.CPP
824 @itemx @var{file}.c++
826 C++ source code which must be preprocessed. Note that in @samp{.cxx},
827 the last two letters must both be literally @samp{x}. Likewise,
828 @samp{.C} refers to a literal capital C@.
832 Objective-C++ source code which must be preprocessed.
835 Objective-C++ source code which should not be preprocessed.
839 C++ header file to be turned into a precompiled header.
842 @itemx @var{file}.for
843 @itemx @var{file}.FOR
844 Fortran source code which should not be preprocessed.
847 @itemx @var{file}.fpp
848 @itemx @var{file}.FPP
849 Fortran source code which must be preprocessed (with the traditional
853 Fortran source code which must be preprocessed with a RATFOR
854 preprocessor (not included with GCC)@.
857 @itemx @var{file}.f95
858 Fortran 90/95 source code which should not be preprocessed.
860 @c FIXME: Descriptions of Java file types.
867 Ada source code file which contains a library unit declaration (a
868 declaration of a package, subprogram, or generic, or a generic
869 instantiation), or a library unit renaming declaration (a package,
870 generic, or subprogram renaming declaration). Such files are also
873 @itemx @var{file}.adb
874 Ada source code file containing a library unit body (a subprogram or
875 package body). Such files are also called @dfn{bodies}.
877 @c GCC also knows about some suffixes for languages not yet included:
886 Assembler code which must be preprocessed.
889 An object file to be fed straight into linking.
890 Any file name with no recognized suffix is treated this way.
894 You can specify the input language explicitly with the @option{-x} option:
897 @item -x @var{language}
898 Specify explicitly the @var{language} for the following input files
899 (rather than letting the compiler choose a default based on the file
900 name suffix). This option applies to all following input files until
901 the next @option{-x} option. Possible values for @var{language} are:
903 c c-header c-cpp-output
904 c++ c++-header c++-cpp-output
905 objective-c objective-c-header objective-c-cpp-output
906 objective-c++ objective-c++-header objective-c++-cpp-output
907 assembler assembler-with-cpp
909 f77 f77-cpp-input ratfor
916 Turn off any specification of a language, so that subsequent files are
917 handled according to their file name suffixes (as they are if @option{-x}
918 has not been used at all).
920 @item -pass-exit-codes
921 @opindex pass-exit-codes
922 Normally the @command{gcc} program will exit with the code of 1 if any
923 phase of the compiler returns a non-success return code. If you specify
924 @option{-pass-exit-codes}, the @command{gcc} program will instead return with
925 numerically highest error produced by any phase that returned an error
929 If you only want some of the stages of compilation, you can use
930 @option{-x} (or filename suffixes) to tell @command{gcc} where to start, and
931 one of the options @option{-c}, @option{-S}, or @option{-E} to say where
932 @command{gcc} is to stop. Note that some combinations (for example,
933 @samp{-x cpp-output -E}) instruct @command{gcc} to do nothing at all.
938 Compile or assemble the source files, but do not link. The linking
939 stage simply is not done. The ultimate output is in the form of an
940 object file for each source file.
942 By default, the object file name for a source file is made by replacing
943 the suffix @samp{.c}, @samp{.i}, @samp{.s}, etc., with @samp{.o}.
945 Unrecognized input files, not requiring compilation or assembly, are
950 Stop after the stage of compilation proper; do not assemble. The output
951 is in the form of an assembler code file for each non-assembler input
954 By default, the assembler file name for a source file is made by
955 replacing the suffix @samp{.c}, @samp{.i}, etc., with @samp{.s}.
957 Input files that don't require compilation are ignored.
961 Stop after the preprocessing stage; do not run the compiler proper. The
962 output is in the form of preprocessed source code, which is sent to the
965 Input files which don't require preprocessing are ignored.
967 @cindex output file option
970 Place output in file @var{file}. This applies regardless to whatever
971 sort of output is being produced, whether it be an executable file,
972 an object file, an assembler file or preprocessed C code.
974 If @option{-o} is not specified, the default is to put an executable
975 file in @file{a.out}, the object file for
976 @file{@var{source}.@var{suffix}} in @file{@var{source}.o}, its
977 assembler file in @file{@var{source}.s}, a precompiled header file in
978 @file{@var{source}.@var{suffix}.gch}, and all preprocessed C source on
983 Print (on standard error output) the commands executed to run the stages
984 of compilation. Also print the version number of the compiler driver
985 program and of the preprocessor and the compiler proper.
989 Like @option{-v} except the commands are not executed and all command
990 arguments are quoted. This is useful for shell scripts to capture the
991 driver-generated command lines.
995 Use pipes rather than temporary files for communication between the
996 various stages of compilation. This fails to work on some systems where
997 the assembler is unable to read from a pipe; but the GNU assembler has
1002 If you are compiling multiple source files, this option tells the driver
1003 to pass all the source files to the compiler at once (for those
1004 languages for which the compiler can handle this). This will allow
1005 intermodule analysis (IMA) to be performed by the compiler. Currently the only
1006 language for which this is supported is C@. If you pass source files for
1007 multiple languages to the driver, using this option, the driver will invoke
1008 the compiler(s) that support IMA once each, passing each compiler all the
1009 source files appropriate for it. For those languages that do not support
1010 IMA this option will be ignored, and the compiler will be invoked once for
1011 each source file in that language. If you use this option in conjunction
1012 with @option{-save-temps}, the compiler will generate multiple
1014 (one for each source file), but only one (combined) @file{.o} or
1019 Print (on the standard output) a description of the command line options
1020 understood by @command{gcc}. If the @option{-v} option is also specified
1021 then @option{--help} will also be passed on to the various processes
1022 invoked by @command{gcc}, so that they can display the command line options
1023 they accept. If the @option{-Wextra} option is also specified then command
1024 line options which have no documentation associated with them will also
1028 @opindex target-help
1029 Print (on the standard output) a description of target specific command
1030 line options for each tool.
1034 Display the version number and copyrights of the invoked GCC@.
1038 @section Compiling C++ Programs
1040 @cindex suffixes for C++ source
1041 @cindex C++ source file suffixes
1042 C++ source files conventionally use one of the suffixes @samp{.C},
1043 @samp{.cc}, @samp{.cpp}, @samp{.CPP}, @samp{.c++}, @samp{.cp}, or
1044 @samp{.cxx}; C++ header files often use @samp{.hh} or @samp{.H}; and
1045 preprocessed C++ files use the suffix @samp{.ii}. GCC recognizes
1046 files with these names and compiles them as C++ programs even if you
1047 call the compiler the same way as for compiling C programs (usually
1048 with the name @command{gcc}).
1052 However, C++ programs often require class libraries as well as a
1053 compiler that understands the C++ language---and under some
1054 circumstances, you might want to compile programs or header files from
1055 standard input, or otherwise without a suffix that flags them as C++
1056 programs. You might also like to precompile a C header file with a
1057 @samp{.h} extension to be used in C++ compilations. @command{g++} is a
1058 program that calls GCC with the default language set to C++, and
1059 automatically specifies linking against the C++ library. On many
1060 systems, @command{g++} is also installed with the name @command{c++}.
1062 @cindex invoking @command{g++}
1063 When you compile C++ programs, you may specify many of the same
1064 command-line options that you use for compiling programs in any
1065 language; or command-line options meaningful for C and related
1066 languages; or options that are meaningful only for C++ programs.
1067 @xref{C Dialect Options,,Options Controlling C Dialect}, for
1068 explanations of options for languages related to C@.
1069 @xref{C++ Dialect Options,,Options Controlling C++ Dialect}, for
1070 explanations of options that are meaningful only for C++ programs.
1072 @node C Dialect Options
1073 @section Options Controlling C Dialect
1074 @cindex dialect options
1075 @cindex language dialect options
1076 @cindex options, dialect
1078 The following options control the dialect of C (or languages derived
1079 from C, such as C++, Objective-C and Objective-C++) that the compiler
1083 @cindex ANSI support
1087 In C mode, support all ISO C90 programs. In C++ mode,
1088 remove GNU extensions that conflict with ISO C++.
1090 This turns off certain features of GCC that are incompatible with ISO
1091 C90 (when compiling C code), or of standard C++ (when compiling C++ code),
1092 such as the @code{asm} and @code{typeof} keywords, and
1093 predefined macros such as @code{unix} and @code{vax} that identify the
1094 type of system you are using. It also enables the undesirable and
1095 rarely used ISO trigraph feature. For the C compiler,
1096 it disables recognition of C++ style @samp{//} comments as well as
1097 the @code{inline} keyword.
1099 The alternate keywords @code{__asm__}, @code{__extension__},
1100 @code{__inline__} and @code{__typeof__} continue to work despite
1101 @option{-ansi}. You would not want to use them in an ISO C program, of
1102 course, but it is useful to put them in header files that might be included
1103 in compilations done with @option{-ansi}. Alternate predefined macros
1104 such as @code{__unix__} and @code{__vax__} are also available, with or
1105 without @option{-ansi}.
1107 The @option{-ansi} option does not cause non-ISO programs to be
1108 rejected gratuitously. For that, @option{-pedantic} is required in
1109 addition to @option{-ansi}. @xref{Warning Options}.
1111 The macro @code{__STRICT_ANSI__} is predefined when the @option{-ansi}
1112 option is used. Some header files may notice this macro and refrain
1113 from declaring certain functions or defining certain macros that the
1114 ISO standard doesn't call for; this is to avoid interfering with any
1115 programs that might use these names for other things.
1117 Functions which would normally be built in but do not have semantics
1118 defined by ISO C (such as @code{alloca} and @code{ffs}) are not built-in
1119 functions with @option{-ansi} is used. @xref{Other Builtins,,Other
1120 built-in functions provided by GCC}, for details of the functions
1125 Determine the language standard. This option is currently only
1126 supported when compiling C or C++. A value for this option must be
1127 provided; possible values are
1132 ISO C90 (same as @option{-ansi}).
1134 @item iso9899:199409
1135 ISO C90 as modified in amendment 1.
1141 ISO C99. Note that this standard is not yet fully supported; see
1142 @w{@uref{http://gcc.gnu.org/c99status.html}} for more information. The
1143 names @samp{c9x} and @samp{iso9899:199x} are deprecated.
1146 Default, ISO C90 plus GNU extensions (including some C99 features).
1150 ISO C99 plus GNU extensions. When ISO C99 is fully implemented in GCC,
1151 this will become the default. The name @samp{gnu9x} is deprecated.
1154 The 1998 ISO C++ standard plus amendments.
1157 The same as @option{-std=c++98} plus GNU extensions. This is the
1158 default for C++ code.
1161 Even when this option is not specified, you can still use some of the
1162 features of newer standards in so far as they do not conflict with
1163 previous C standards. For example, you may use @code{__restrict__} even
1164 when @option{-std=c99} is not specified.
1166 The @option{-std} options specifying some version of ISO C have the same
1167 effects as @option{-ansi}, except that features that were not in ISO C90
1168 but are in the specified version (for example, @samp{//} comments and
1169 the @code{inline} keyword in ISO C99) are not disabled.
1171 @xref{Standards,,Language Standards Supported by GCC}, for details of
1172 these standard versions.
1174 @item -aux-info @var{filename}
1176 Output to the given filename prototyped declarations for all functions
1177 declared and/or defined in a translation unit, including those in header
1178 files. This option is silently ignored in any language other than C@.
1180 Besides declarations, the file indicates, in comments, the origin of
1181 each declaration (source file and line), whether the declaration was
1182 implicit, prototyped or unprototyped (@samp{I}, @samp{N} for new or
1183 @samp{O} for old, respectively, in the first character after the line
1184 number and the colon), and whether it came from a declaration or a
1185 definition (@samp{C} or @samp{F}, respectively, in the following
1186 character). In the case of function definitions, a K&R-style list of
1187 arguments followed by their declarations is also provided, inside
1188 comments, after the declaration.
1192 Do not recognize @code{asm}, @code{inline} or @code{typeof} as a
1193 keyword, so that code can use these words as identifiers. You can use
1194 the keywords @code{__asm__}, @code{__inline__} and @code{__typeof__}
1195 instead. @option{-ansi} implies @option{-fno-asm}.
1197 In C++, this switch only affects the @code{typeof} keyword, since
1198 @code{asm} and @code{inline} are standard keywords. You may want to
1199 use the @option{-fno-gnu-keywords} flag instead, which has the same
1200 effect. In C99 mode (@option{-std=c99} or @option{-std=gnu99}), this
1201 switch only affects the @code{asm} and @code{typeof} keywords, since
1202 @code{inline} is a standard keyword in ISO C99.
1205 @itemx -fno-builtin-@var{function}
1206 @opindex fno-builtin
1207 @cindex built-in functions
1208 Don't recognize built-in functions that do not begin with
1209 @samp{__builtin_} as prefix. @xref{Other Builtins,,Other built-in
1210 functions provided by GCC}, for details of the functions affected,
1211 including those which are not built-in functions when @option{-ansi} or
1212 @option{-std} options for strict ISO C conformance are used because they
1213 do not have an ISO standard meaning.
1215 GCC normally generates special code to handle certain built-in functions
1216 more efficiently; for instance, calls to @code{alloca} may become single
1217 instructions that adjust the stack directly, and calls to @code{memcpy}
1218 may become inline copy loops. The resulting code is often both smaller
1219 and faster, but since the function calls no longer appear as such, you
1220 cannot set a breakpoint on those calls, nor can you change the behavior
1221 of the functions by linking with a different library. In addition,
1222 when a function is recognized as a built-in function, GCC may use
1223 information about that function to warn about problems with calls to
1224 that function, or to generate more efficient code, even if the
1225 resulting code still contains calls to that function. For example,
1226 warnings are given with @option{-Wformat} for bad calls to
1227 @code{printf}, when @code{printf} is built in, and @code{strlen} is
1228 known not to modify global memory.
1230 With the @option{-fno-builtin-@var{function}} option
1231 only the built-in function @var{function} is
1232 disabled. @var{function} must not begin with @samp{__builtin_}. If a
1233 function is named this is not built-in in this version of GCC, this
1234 option is ignored. There is no corresponding
1235 @option{-fbuiltin-@var{function}} option; if you wish to enable
1236 built-in functions selectively when using @option{-fno-builtin} or
1237 @option{-ffreestanding}, you may define macros such as:
1240 #define abs(n) __builtin_abs ((n))
1241 #define strcpy(d, s) __builtin_strcpy ((d), (s))
1246 @cindex hosted environment
1248 Assert that compilation takes place in a hosted environment. This implies
1249 @option{-fbuiltin}. A hosted environment is one in which the
1250 entire standard library is available, and in which @code{main} has a return
1251 type of @code{int}. Examples are nearly everything except a kernel.
1252 This is equivalent to @option{-fno-freestanding}.
1254 @item -ffreestanding
1255 @opindex ffreestanding
1256 @cindex hosted environment
1258 Assert that compilation takes place in a freestanding environment. This
1259 implies @option{-fno-builtin}. A freestanding environment
1260 is one in which the standard library may not exist, and program startup may
1261 not necessarily be at @code{main}. The most obvious example is an OS kernel.
1262 This is equivalent to @option{-fno-hosted}.
1264 @xref{Standards,,Language Standards Supported by GCC}, for details of
1265 freestanding and hosted environments.
1267 @item -fms-extensions
1268 @opindex fms-extensions
1269 Accept some non-standard constructs used in Microsoft header files.
1271 Some cases of unnamed fields in structures and unions are only
1272 accepted with this option. @xref{Unnamed Fields,,Unnamed struct/union
1273 fields within structs/unions}, for details.
1277 Support ISO C trigraphs. The @option{-ansi} option (and @option{-std}
1278 options for strict ISO C conformance) implies @option{-trigraphs}.
1280 @item -no-integrated-cpp
1281 @opindex no-integrated-cpp
1282 Performs a compilation in two passes: preprocessing and compiling. This
1283 option allows a user supplied "cc1", "cc1plus", or "cc1obj" via the
1284 @option{-B} option. The user supplied compilation step can then add in
1285 an additional preprocessing step after normal preprocessing but before
1286 compiling. The default is to use the integrated cpp (internal cpp)
1288 The semantics of this option will change if "cc1", "cc1plus", and
1289 "cc1obj" are merged.
1291 @cindex traditional C language
1292 @cindex C language, traditional
1294 @itemx -traditional-cpp
1295 @opindex traditional-cpp
1296 @opindex traditional
1297 Formerly, these options caused GCC to attempt to emulate a pre-standard
1298 C compiler. They are now only supported with the @option{-E} switch.
1299 The preprocessor continues to support a pre-standard mode. See the GNU
1300 CPP manual for details.
1302 @item -fcond-mismatch
1303 @opindex fcond-mismatch
1304 Allow conditional expressions with mismatched types in the second and
1305 third arguments. The value of such an expression is void. This option
1306 is not supported for C++.
1308 @item -funsigned-char
1309 @opindex funsigned-char
1310 Let the type @code{char} be unsigned, like @code{unsigned char}.
1312 Each kind of machine has a default for what @code{char} should
1313 be. It is either like @code{unsigned char} by default or like
1314 @code{signed char} by default.
1316 Ideally, a portable program should always use @code{signed char} or
1317 @code{unsigned char} when it depends on the signedness of an object.
1318 But many programs have been written to use plain @code{char} and
1319 expect it to be signed, or expect it to be unsigned, depending on the
1320 machines they were written for. This option, and its inverse, let you
1321 make such a program work with the opposite default.
1323 The type @code{char} is always a distinct type from each of
1324 @code{signed char} or @code{unsigned char}, even though its behavior
1325 is always just like one of those two.
1328 @opindex fsigned-char
1329 Let the type @code{char} be signed, like @code{signed char}.
1331 Note that this is equivalent to @option{-fno-unsigned-char}, which is
1332 the negative form of @option{-funsigned-char}. Likewise, the option
1333 @option{-fno-signed-char} is equivalent to @option{-funsigned-char}.
1335 @item -fsigned-bitfields
1336 @itemx -funsigned-bitfields
1337 @itemx -fno-signed-bitfields
1338 @itemx -fno-unsigned-bitfields
1339 @opindex fsigned-bitfields
1340 @opindex funsigned-bitfields
1341 @opindex fno-signed-bitfields
1342 @opindex fno-unsigned-bitfields
1343 These options control whether a bit-field is signed or unsigned, when the
1344 declaration does not use either @code{signed} or @code{unsigned}. By
1345 default, such a bit-field is signed, because this is consistent: the
1346 basic integer types such as @code{int} are signed types.
1349 @node C++ Dialect Options
1350 @section Options Controlling C++ Dialect
1352 @cindex compiler options, C++
1353 @cindex C++ options, command line
1354 @cindex options, C++
1355 This section describes the command-line options that are only meaningful
1356 for C++ programs; but you can also use most of the GNU compiler options
1357 regardless of what language your program is in. For example, you
1358 might compile a file @code{firstClass.C} like this:
1361 g++ -g -frepo -O -c firstClass.C
1365 In this example, only @option{-frepo} is an option meant
1366 only for C++ programs; you can use the other options with any
1367 language supported by GCC@.
1369 Here is a list of options that are @emph{only} for compiling C++ programs:
1373 @item -fabi-version=@var{n}
1374 @opindex fabi-version
1375 Use version @var{n} of the C++ ABI@. Version 2 is the version of the
1376 C++ ABI that first appeared in G++ 3.4. Version 1 is the version of
1377 the C++ ABI that first appeared in G++ 3.2. Version 0 will always be
1378 the version that conforms most closely to the C++ ABI specification.
1379 Therefore, the ABI obtained using version 0 will change as ABI bugs
1382 The default is version 2.
1384 @item -fno-access-control
1385 @opindex fno-access-control
1386 Turn off all access checking. This switch is mainly useful for working
1387 around bugs in the access control code.
1391 Check that the pointer returned by @code{operator new} is non-null
1392 before attempting to modify the storage allocated. This check is
1393 normally unnecessary because the C++ standard specifies that
1394 @code{operator new} will only return @code{0} if it is declared
1395 @samp{throw()}, in which case the compiler will always check the
1396 return value even without this option. In all other cases, when
1397 @code{operator new} has a non-empty exception specification, memory
1398 exhaustion is signalled by throwing @code{std::bad_alloc}. See also
1399 @samp{new (nothrow)}.
1401 @item -fconserve-space
1402 @opindex fconserve-space
1403 Put uninitialized or runtime-initialized global variables into the
1404 common segment, as C does. This saves space in the executable at the
1405 cost of not diagnosing duplicate definitions. If you compile with this
1406 flag and your program mysteriously crashes after @code{main()} has
1407 completed, you may have an object that is being destroyed twice because
1408 two definitions were merged.
1410 This option is no longer useful on most targets, now that support has
1411 been added for putting variables into BSS without making them common.
1413 @item -fno-const-strings
1414 @opindex fno-const-strings
1415 Give string constants type @code{char *} instead of type @code{const
1416 char *}. By default, G++ uses type @code{const char *} as required by
1417 the standard. Even if you use @option{-fno-const-strings}, you cannot
1418 actually modify the value of a string constant.
1420 This option might be removed in a future release of G++. For maximum
1421 portability, you should structure your code so that it works with
1422 string constants that have type @code{const char *}.
1424 @item -fno-elide-constructors
1425 @opindex fno-elide-constructors
1426 The C++ standard allows an implementation to omit creating a temporary
1427 which is only used to initialize another object of the same type.
1428 Specifying this option disables that optimization, and forces G++ to
1429 call the copy constructor in all cases.
1431 @item -fno-enforce-eh-specs
1432 @opindex fno-enforce-eh-specs
1433 Don't check for violation of exception specifications at runtime. This
1434 option violates the C++ standard, but may be useful for reducing code
1435 size in production builds, much like defining @samp{NDEBUG}. The compiler
1436 will still optimize based on the exception specifications.
1439 @itemx -fno-for-scope
1441 @opindex fno-for-scope
1442 If @option{-ffor-scope} is specified, the scope of variables declared in
1443 a @i{for-init-statement} is limited to the @samp{for} loop itself,
1444 as specified by the C++ standard.
1445 If @option{-fno-for-scope} is specified, the scope of variables declared in
1446 a @i{for-init-statement} extends to the end of the enclosing scope,
1447 as was the case in old versions of G++, and other (traditional)
1448 implementations of C++.
1450 The default if neither flag is given to follow the standard,
1451 but to allow and give a warning for old-style code that would
1452 otherwise be invalid, or have different behavior.
1454 @item -fno-gnu-keywords
1455 @opindex fno-gnu-keywords
1456 Do not recognize @code{typeof} as a keyword, so that code can use this
1457 word as an identifier. You can use the keyword @code{__typeof__} instead.
1458 @option{-ansi} implies @option{-fno-gnu-keywords}.
1460 @item -fno-implicit-templates
1461 @opindex fno-implicit-templates
1462 Never emit code for non-inline templates which are instantiated
1463 implicitly (i.e.@: by use); only emit code for explicit instantiations.
1464 @xref{Template Instantiation}, for more information.
1466 @item -fno-implicit-inline-templates
1467 @opindex fno-implicit-inline-templates
1468 Don't emit code for implicit instantiations of inline templates, either.
1469 The default is to handle inlines differently so that compiles with and
1470 without optimization will need the same set of explicit instantiations.
1472 @item -fno-implement-inlines
1473 @opindex fno-implement-inlines
1474 To save space, do not emit out-of-line copies of inline functions
1475 controlled by @samp{#pragma implementation}. This will cause linker
1476 errors if these functions are not inlined everywhere they are called.
1478 @item -fms-extensions
1479 @opindex fms-extensions
1480 Disable pedantic warnings about constructs used in MFC, such as implicit
1481 int and getting a pointer to member function via non-standard syntax.
1483 @item -fno-nonansi-builtins
1484 @opindex fno-nonansi-builtins
1485 Disable built-in declarations of functions that are not mandated by
1486 ANSI/ISO C@. These include @code{ffs}, @code{alloca}, @code{_exit},
1487 @code{index}, @code{bzero}, @code{conjf}, and other related functions.
1489 @item -fno-operator-names
1490 @opindex fno-operator-names
1491 Do not treat the operator name keywords @code{and}, @code{bitand},
1492 @code{bitor}, @code{compl}, @code{not}, @code{or} and @code{xor} as
1493 synonyms as keywords.
1495 @item -fno-optional-diags
1496 @opindex fno-optional-diags
1497 Disable diagnostics that the standard says a compiler does not need to
1498 issue. Currently, the only such diagnostic issued by G++ is the one for
1499 a name having multiple meanings within a class.
1502 @opindex fpermissive
1503 Downgrade some diagnostics about nonconformant code from errors to
1504 warnings. Thus, using @option{-fpermissive} will allow some
1505 nonconforming code to compile.
1509 Enable automatic template instantiation at link time. This option also
1510 implies @option{-fno-implicit-templates}. @xref{Template
1511 Instantiation}, for more information.
1515 Disable generation of information about every class with virtual
1516 functions for use by the C++ runtime type identification features
1517 (@samp{dynamic_cast} and @samp{typeid}). If you don't use those parts
1518 of the language, you can save some space by using this flag. Note that
1519 exception handling uses the same information, but it will generate it as
1524 Emit statistics about front-end processing at the end of the compilation.
1525 This information is generally only useful to the G++ development team.
1527 @item -ftemplate-depth-@var{n}
1528 @opindex ftemplate-depth
1529 Set the maximum instantiation depth for template classes to @var{n}.
1530 A limit on the template instantiation depth is needed to detect
1531 endless recursions during template class instantiation. ANSI/ISO C++
1532 conforming programs must not rely on a maximum depth greater than 17.
1534 @item -fno-threadsafe-statics
1535 @opindex fno-threadsafe-statics
1536 Do not emit the extra code to use the routines specified in the C++
1537 ABI for thread-safe initialization of local statics. You can use this
1538 option to reduce code size slightly in code that doesn't need to be
1541 @item -fuse-cxa-atexit
1542 @opindex fuse-cxa-atexit
1543 Register destructors for objects with static storage duration with the
1544 @code{__cxa_atexit} function rather than the @code{atexit} function.
1545 This option is required for fully standards-compliant handling of static
1546 destructors, but will only work if your C library supports
1547 @code{__cxa_atexit}.
1549 @item -fvisibility-inlines-hidden
1550 @opindex fvisibility-inlines-hidden
1551 Causes all inlined methods to be marked with
1552 @code{__attribute__ ((visibility ("hidden")))} so that they do not
1553 appear in the export table of a DSO and do not require a PLT indirection
1554 when used within the DSO@. Enabling this option can have a dramatic effect
1555 on load and link times of a DSO as it massively reduces the size of the
1556 dynamic export table when the library makes heavy use of templates. While
1557 it can cause bloating through duplication of code within each DSO where
1558 it is used, often the wastage is less than the considerable space occupied
1559 by a long symbol name in the export table which is typical when using
1560 templates and namespaces. For even more savings, combine with the
1561 @option{-fvisibility=hidden} switch.
1565 Do not use weak symbol support, even if it is provided by the linker.
1566 By default, G++ will use weak symbols if they are available. This
1567 option exists only for testing, and should not be used by end-users;
1568 it will result in inferior code and has no benefits. This option may
1569 be removed in a future release of G++.
1573 Do not search for header files in the standard directories specific to
1574 C++, but do still search the other standard directories. (This option
1575 is used when building the C++ library.)
1578 In addition, these optimization, warning, and code generation options
1579 have meanings only for C++ programs:
1582 @item -fno-default-inline
1583 @opindex fno-default-inline
1584 Do not assume @samp{inline} for functions defined inside a class scope.
1585 @xref{Optimize Options,,Options That Control Optimization}. Note that these
1586 functions will have linkage like inline functions; they just won't be
1589 @item -Wabi @r{(C++ only)}
1591 Warn when G++ generates code that is probably not compatible with the
1592 vendor-neutral C++ ABI@. Although an effort has been made to warn about
1593 all such cases, there are probably some cases that are not warned about,
1594 even though G++ is generating incompatible code. There may also be
1595 cases where warnings are emitted even though the code that is generated
1598 You should rewrite your code to avoid these warnings if you are
1599 concerned about the fact that code generated by G++ may not be binary
1600 compatible with code generated by other compilers.
1602 The known incompatibilities at this point include:
1607 Incorrect handling of tail-padding for bit-fields. G++ may attempt to
1608 pack data into the same byte as a base class. For example:
1611 struct A @{ virtual void f(); int f1 : 1; @};
1612 struct B : public A @{ int f2 : 1; @};
1616 In this case, G++ will place @code{B::f2} into the same byte
1617 as@code{A::f1}; other compilers will not. You can avoid this problem
1618 by explicitly padding @code{A} so that its size is a multiple of the
1619 byte size on your platform; that will cause G++ and other compilers to
1620 layout @code{B} identically.
1623 Incorrect handling of tail-padding for virtual bases. G++ does not use
1624 tail padding when laying out virtual bases. For example:
1627 struct A @{ virtual void f(); char c1; @};
1628 struct B @{ B(); char c2; @};
1629 struct C : public A, public virtual B @{@};
1633 In this case, G++ will not place @code{B} into the tail-padding for
1634 @code{A}; other compilers will. You can avoid this problem by
1635 explicitly padding @code{A} so that its size is a multiple of its
1636 alignment (ignoring virtual base classes); that will cause G++ and other
1637 compilers to layout @code{C} identically.
1640 Incorrect handling of bit-fields with declared widths greater than that
1641 of their underlying types, when the bit-fields appear in a union. For
1645 union U @{ int i : 4096; @};
1649 Assuming that an @code{int} does not have 4096 bits, G++ will make the
1650 union too small by the number of bits in an @code{int}.
1653 Empty classes can be placed at incorrect offsets. For example:
1663 struct C : public B, public A @{@};
1667 G++ will place the @code{A} base class of @code{C} at a nonzero offset;
1668 it should be placed at offset zero. G++ mistakenly believes that the
1669 @code{A} data member of @code{B} is already at offset zero.
1672 Names of template functions whose types involve @code{typename} or
1673 template template parameters can be mangled incorrectly.
1676 template <typename Q>
1677 void f(typename Q::X) @{@}
1679 template <template <typename> class Q>
1680 void f(typename Q<int>::X) @{@}
1684 Instantiations of these templates may be mangled incorrectly.
1688 @item -Wctor-dtor-privacy @r{(C++ only)}
1689 @opindex Wctor-dtor-privacy
1690 Warn when a class seems unusable because all the constructors or
1691 destructors in that class are private, and it has neither friends nor
1692 public static member functions.
1694 @item -Wnon-virtual-dtor @r{(C++ only)}
1695 @opindex Wnon-virtual-dtor
1696 Warn when a class appears to be polymorphic, thereby requiring a virtual
1697 destructor, yet it declares a non-virtual one.
1698 This warning is enabled by @option{-Wall}.
1700 @item -Wreorder @r{(C++ only)}
1702 @cindex reordering, warning
1703 @cindex warning for reordering of member initializers
1704 Warn when the order of member initializers given in the code does not
1705 match the order in which they must be executed. For instance:
1711 A(): j (0), i (1) @{ @}
1715 The compiler will rearrange the member initializers for @samp{i}
1716 and @samp{j} to match the declaration order of the members, emitting
1717 a warning to that effect. This warning is enabled by @option{-Wall}.
1720 The following @option{-W@dots{}} options are not affected by @option{-Wall}.
1723 @item -Weffc++ @r{(C++ only)}
1725 Warn about violations of the following style guidelines from Scott Meyers'
1726 @cite{Effective C++} book:
1730 Item 11: Define a copy constructor and an assignment operator for classes
1731 with dynamically allocated memory.
1734 Item 12: Prefer initialization to assignment in constructors.
1737 Item 14: Make destructors virtual in base classes.
1740 Item 15: Have @code{operator=} return a reference to @code{*this}.
1743 Item 23: Don't try to return a reference when you must return an object.
1747 Also warn about violations of the following style guidelines from
1748 Scott Meyers' @cite{More Effective C++} book:
1752 Item 6: Distinguish between prefix and postfix forms of increment and
1753 decrement operators.
1756 Item 7: Never overload @code{&&}, @code{||}, or @code{,}.
1760 When selecting this option, be aware that the standard library
1761 headers do not obey all of these guidelines; use @samp{grep -v}
1762 to filter out those warnings.
1764 @item -Wno-deprecated @r{(C++ only)}
1765 @opindex Wno-deprecated
1766 Do not warn about usage of deprecated features. @xref{Deprecated Features}.
1768 @item -Wstrict-null-sentinel @r{(C++ only)}
1769 @opindex Wstrict-null-sentinel
1770 Warn also about the use of an uncasted @code{NULL} as sentinel. When
1771 compiling only with GCC this is a valid sentinel, as @code{NULL} is defined
1772 to @code{__null}. Although it is a null pointer constant not a null pointer,
1773 it is guaranteed to of the same size as a pointer. But this use is
1774 not portable across different compilers.
1776 @item -Wno-non-template-friend @r{(C++ only)}
1777 @opindex Wno-non-template-friend
1778 Disable warnings when non-templatized friend functions are declared
1779 within a template. Since the advent of explicit template specification
1780 support in G++, if the name of the friend is an unqualified-id (i.e.,
1781 @samp{friend foo(int)}), the C++ language specification demands that the
1782 friend declare or define an ordinary, nontemplate function. (Section
1783 14.5.3). Before G++ implemented explicit specification, unqualified-ids
1784 could be interpreted as a particular specialization of a templatized
1785 function. Because this non-conforming behavior is no longer the default
1786 behavior for G++, @option{-Wnon-template-friend} allows the compiler to
1787 check existing code for potential trouble spots and is on by default.
1788 This new compiler behavior can be turned off with
1789 @option{-Wno-non-template-friend} which keeps the conformant compiler code
1790 but disables the helpful warning.
1792 @item -Wold-style-cast @r{(C++ only)}
1793 @opindex Wold-style-cast
1794 Warn if an old-style (C-style) cast to a non-void type is used within
1795 a C++ program. The new-style casts (@samp{static_cast},
1796 @samp{reinterpret_cast}, and @samp{const_cast}) are less vulnerable to
1797 unintended effects and much easier to search for.
1799 @item -Woverloaded-virtual @r{(C++ only)}
1800 @opindex Woverloaded-virtual
1801 @cindex overloaded virtual fn, warning
1802 @cindex warning for overloaded virtual fn
1803 Warn when a function declaration hides virtual functions from a
1804 base class. For example, in:
1811 struct B: public A @{
1816 the @code{A} class version of @code{f} is hidden in @code{B}, and code
1824 will fail to compile.
1826 @item -Wno-pmf-conversions @r{(C++ only)}
1827 @opindex Wno-pmf-conversions
1828 Disable the diagnostic for converting a bound pointer to member function
1831 @item -Wsign-promo @r{(C++ only)}
1832 @opindex Wsign-promo
1833 Warn when overload resolution chooses a promotion from unsigned or
1834 enumerated type to a signed type, over a conversion to an unsigned type of
1835 the same size. Previous versions of G++ would try to preserve
1836 unsignedness, but the standard mandates the current behavior.
1841 A& operator = (int);
1851 In this example, G++ will synthesize a default @samp{A& operator =
1852 (const A&);}, while cfront will use the user-defined @samp{operator =}.
1855 @node Objective-C and Objective-C++ Dialect Options
1856 @section Options Controlling Objective-C and Objective-C++ Dialects
1858 @cindex compiler options, Objective-C and Objective-C++
1859 @cindex Objective-C and Objective-C++ options, command line
1860 @cindex options, Objective-C and Objective-C++
1861 (NOTE: This manual does not describe the Objective-C and Objective-C++
1862 languages themselves. See @xref{Standards,,Language Standards
1863 Supported by GCC}, for references.)
1865 This section describes the command-line options that are only meaningful
1866 for Objective-C and Objective-C++ programs, but you can also use most of
1867 the language-independent GNU compiler options.
1868 For example, you might compile a file @code{some_class.m} like this:
1871 gcc -g -fgnu-runtime -O -c some_class.m
1875 In this example, @option{-fgnu-runtime} is an option meant only for
1876 Objective-C and Objective-C++ programs; you can use the other options with
1877 any language supported by GCC@.
1879 Note that since Objective-C is an extension of the C language, Objective-C
1880 compilations may also use options specific to the C front-end (e.g.,
1881 @option{-Wtraditional}). Similarly, Objective-C++ compilations may use
1882 C++-specific options (e.g., @option{-Wabi}).
1884 Here is a list of options that are @emph{only} for compiling Objective-C
1885 and Objective-C++ programs:
1888 @item -fconstant-string-class=@var{class-name}
1889 @opindex fconstant-string-class
1890 Use @var{class-name} as the name of the class to instantiate for each
1891 literal string specified with the syntax @code{@@"@dots{}"}. The default
1892 class name is @code{NXConstantString} if the GNU runtime is being used, and
1893 @code{NSConstantString} if the NeXT runtime is being used (see below). The
1894 @option{-fconstant-cfstrings} option, if also present, will override the
1895 @option{-fconstant-string-class} setting and cause @code{@@"@dots{}"} literals
1896 to be laid out as constant CoreFoundation strings.
1899 @opindex fgnu-runtime
1900 Generate object code compatible with the standard GNU Objective-C
1901 runtime. This is the default for most types of systems.
1903 @item -fnext-runtime
1904 @opindex fnext-runtime
1905 Generate output compatible with the NeXT runtime. This is the default
1906 for NeXT-based systems, including Darwin and Mac OS X@. The macro
1907 @code{__NEXT_RUNTIME__} is predefined if (and only if) this option is
1910 @item -fno-nil-receivers
1911 @opindex fno-nil-receivers
1912 Assume that all Objective-C message dispatches (e.g.,
1913 @code{[receiver message:arg]}) in this translation unit ensure that the receiver
1914 is not @code{nil}. This allows for more efficient entry points in the runtime
1915 to be used. Currently, this option is only available in conjunction with
1916 the NeXT runtime on Mac OS X 10.3 and later.
1918 @item -fobjc-call-cxx-cdtors
1919 @opindex fobjc-call-cxx-cdtors
1920 For each Objective-C class, check if any of its instance variables is a
1921 C++ object with a non-trivial default constructor. If so, synthesize a
1922 special @code{- (id) .cxx_construct} instance method that will run
1923 non-trivial default constructors on any such instance variables, in order,
1924 and then return @code{self}. Similarly, check if any instance variable
1925 is a C++ object with a non-trivial destructor, and if so, synthesize a
1926 special @code{- (void) .cxx_destruct} method that will run
1927 all such default destructors, in reverse order.
1929 The @code{- (id) .cxx_construct} and/or @code{- (void) .cxx_destruct} methods
1930 thusly generated will only operate on instance variables declared in the
1931 current Objective-C class, and not those inherited from superclasses. It
1932 is the responsibility of the Objective-C runtime to invoke all such methods
1933 in an object's inheritance hierarchy. The @code{- (id) .cxx_construct} methods
1934 will be invoked by the runtime immediately after a new object
1935 instance is allocated; the @code{- (void) .cxx_destruct} methods will
1936 be invoked immediately before the runtime deallocates an object instance.
1938 As of this writing, only the NeXT runtime on Mac OS X 10.4 and later has
1939 support for invoking the @code{- (id) .cxx_construct} and
1940 @code{- (void) .cxx_destruct} methods.
1942 @item -fobjc-direct-dispatch
1943 @opindex fobjc-direct-dispatch
1944 Allow fast jumps to the message dispatcher. On Darwin this is
1945 accomplished via the comm page.
1947 @item -fobjc-exceptions
1948 @opindex fobjc-exceptions
1949 Enable syntactic support for structured exception handling in Objective-C,
1950 similar to what is offered by C++ and Java. Currently, this option is only
1951 available in conjunction with the NeXT runtime on Mac OS X 10.3 and later.
1959 @@catch (AnObjCClass *exc) @{
1966 @@catch (AnotherClass *exc) @{
1969 @@catch (id allOthers) @{
1979 The @code{@@throw} statement may appear anywhere in an Objective-C or
1980 Objective-C++ program; when used inside of a @code{@@catch} block, the
1981 @code{@@throw} may appear without an argument (as shown above), in which case
1982 the object caught by the @code{@@catch} will be rethrown.
1984 Note that only (pointers to) Objective-C objects may be thrown and
1985 caught using this scheme. When an object is thrown, it will be caught
1986 by the nearest @code{@@catch} clause capable of handling objects of that type,
1987 analogously to how @code{catch} blocks work in C++ and Java. A
1988 @code{@@catch(id @dots{})} clause (as shown above) may also be provided to catch
1989 any and all Objective-C exceptions not caught by previous @code{@@catch}
1992 The @code{@@finally} clause, if present, will be executed upon exit from the
1993 immediately preceding @code{@@try @dots{} @@catch} section. This will happen
1994 regardless of whether any exceptions are thrown, caught or rethrown
1995 inside the @code{@@try @dots{} @@catch} section, analogously to the behavior
1996 of the @code{finally} clause in Java.
1998 There are several caveats to using the new exception mechanism:
2002 Although currently designed to be binary compatible with @code{NS_HANDLER}-style
2003 idioms provided by the @code{NSException} class, the new
2004 exceptions can only be used on Mac OS X 10.3 (Panther) and later
2005 systems, due to additional functionality needed in the (NeXT) Objective-C
2009 As mentioned above, the new exceptions do not support handling
2010 types other than Objective-C objects. Furthermore, when used from
2011 Objective-C++, the Objective-C exception model does not interoperate with C++
2012 exceptions at this time. This means you cannot @code{@@throw} an exception
2013 from Objective-C and @code{catch} it in C++, or vice versa
2014 (i.e., @code{throw @dots{} @@catch}).
2017 The @option{-fobjc-exceptions} switch also enables the use of synchronization
2018 blocks for thread-safe execution:
2021 @@synchronized (ObjCClass *guard) @{
2026 Upon entering the @code{@@synchronized} block, a thread of execution shall
2027 first check whether a lock has been placed on the corresponding @code{guard}
2028 object by another thread. If it has, the current thread shall wait until
2029 the other thread relinquishes its lock. Once @code{guard} becomes available,
2030 the current thread will place its own lock on it, execute the code contained in
2031 the @code{@@synchronized} block, and finally relinquish the lock (thereby
2032 making @code{guard} available to other threads).
2034 Unlike Java, Objective-C does not allow for entire methods to be marked
2035 @code{@@synchronized}. Note that throwing exceptions out of
2036 @code{@@synchronized} blocks is allowed, and will cause the guarding object
2037 to be unlocked properly.
2041 Enable garbage collection (GC) in Objective-C and Objective-C++ programs.
2043 @item -freplace-objc-classes
2044 @opindex freplace-objc-classes
2045 Emit a special marker instructing @command{ld(1)} not to statically link in
2046 the resulting object file, and allow @command{dyld(1)} to load it in at
2047 run time instead. This is used in conjunction with the Fix-and-Continue
2048 debugging mode, where the object file in question may be recompiled and
2049 dynamically reloaded in the course of program execution, without the need
2050 to restart the program itself. Currently, Fix-and-Continue functionality
2051 is only available in conjunction with the NeXT runtime on Mac OS X 10.3
2056 When compiling for the NeXT runtime, the compiler ordinarily replaces calls
2057 to @code{objc_getClass("@dots{}")} (when the name of the class is known at
2058 compile time) with static class references that get initialized at load time,
2059 which improves run-time performance. Specifying the @option{-fzero-link} flag
2060 suppresses this behavior and causes calls to @code{objc_getClass("@dots{}")}
2061 to be retained. This is useful in Zero-Link debugging mode, since it allows
2062 for individual class implementations to be modified during program execution.
2066 Dump interface declarations for all classes seen in the source file to a
2067 file named @file{@var{sourcename}.decl}.
2069 @item -Wassign-intercept
2070 @opindex Wassign-intercept
2071 Warn whenever an Objective-C assignment is being intercepted by the
2075 @opindex Wno-protocol
2076 If a class is declared to implement a protocol, a warning is issued for
2077 every method in the protocol that is not implemented by the class. The
2078 default behavior is to issue a warning for every method not explicitly
2079 implemented in the class, even if a method implementation is inherited
2080 from the superclass. If you use the @option{-Wno-protocol} option, then
2081 methods inherited from the superclass are considered to be implemented,
2082 and no warning is issued for them.
2086 Warn if multiple methods of different types for the same selector are
2087 found during compilation. The check is performed on the list of methods
2088 in the final stage of compilation. Additionally, a check is performed
2089 for each selector appearing in a @code{@@selector(@dots{})}
2090 expression, and a corresponding method for that selector has been found
2091 during compilation. Because these checks scan the method table only at
2092 the end of compilation, these warnings are not produced if the final
2093 stage of compilation is not reached, for example because an error is
2094 found during compilation, or because the @option{-fsyntax-only} option is
2097 @item -Wstrict-selector-match
2098 @opindex Wstrict-selector-match
2099 Warn if multiple methods with differing argument and/or return types are
2100 found for a given selector when attempting to send a message using this
2101 selector to a receiver of type @code{id} or @code{Class}. When this flag
2102 is off (which is the default behavior), the compiler will omit such warnings
2103 if any differences found are confined to types which share the same size
2106 @item -Wundeclared-selector
2107 @opindex Wundeclared-selector
2108 Warn if a @code{@@selector(@dots{})} expression referring to an
2109 undeclared selector is found. A selector is considered undeclared if no
2110 method with that name has been declared before the
2111 @code{@@selector(@dots{})} expression, either explicitly in an
2112 @code{@@interface} or @code{@@protocol} declaration, or implicitly in
2113 an @code{@@implementation} section. This option always performs its
2114 checks as soon as a @code{@@selector(@dots{})} expression is found,
2115 while @option{-Wselector} only performs its checks in the final stage of
2116 compilation. This also enforces the coding style convention
2117 that methods and selectors must be declared before being used.
2119 @item -print-objc-runtime-info
2120 @opindex print-objc-runtime-info
2121 Generate C header describing the largest structure that is passed by
2126 @node Language Independent Options
2127 @section Options to Control Diagnostic Messages Formatting
2128 @cindex options to control diagnostics formatting
2129 @cindex diagnostic messages
2130 @cindex message formatting
2132 Traditionally, diagnostic messages have been formatted irrespective of
2133 the output device's aspect (e.g.@: its width, @dots{}). The options described
2134 below can be used to control the diagnostic messages formatting
2135 algorithm, e.g.@: how many characters per line, how often source location
2136 information should be reported. Right now, only the C++ front end can
2137 honor these options. However it is expected, in the near future, that
2138 the remaining front ends would be able to digest them correctly.
2141 @item -fmessage-length=@var{n}
2142 @opindex fmessage-length
2143 Try to format error messages so that they fit on lines of about @var{n}
2144 characters. The default is 72 characters for @command{g++} and 0 for the rest of
2145 the front ends supported by GCC@. If @var{n} is zero, then no
2146 line-wrapping will be done; each error message will appear on a single
2149 @opindex fdiagnostics-show-location
2150 @item -fdiagnostics-show-location=once
2151 Only meaningful in line-wrapping mode. Instructs the diagnostic messages
2152 reporter to emit @emph{once} source location information; that is, in
2153 case the message is too long to fit on a single physical line and has to
2154 be wrapped, the source location won't be emitted (as prefix) again,
2155 over and over, in subsequent continuation lines. This is the default
2158 @item -fdiagnostics-show-location=every-line
2159 Only meaningful in line-wrapping mode. Instructs the diagnostic
2160 messages reporter to emit the same source location information (as
2161 prefix) for physical lines that result from the process of breaking
2162 a message which is too long to fit on a single line.
2164 @item -fdiagnostics-show-options
2165 @opindex fdiagnostics-show-options
2166 This option instructs the diagnostic machinery to add text to each
2167 diagnostic emitted, which indicates which command line option directly
2168 controls that diagnostic, when such an option is known to the
2169 diagnostic machinery.
2173 @node Warning Options
2174 @section Options to Request or Suppress Warnings
2175 @cindex options to control warnings
2176 @cindex warning messages
2177 @cindex messages, warning
2178 @cindex suppressing warnings
2180 Warnings are diagnostic messages that report constructions which
2181 are not inherently erroneous but which are risky or suggest there
2182 may have been an error.
2184 You can request many specific warnings with options beginning @samp{-W},
2185 for example @option{-Wimplicit} to request warnings on implicit
2186 declarations. Each of these specific warning options also has a
2187 negative form beginning @samp{-Wno-} to turn off warnings;
2188 for example, @option{-Wno-implicit}. This manual lists only one of the
2189 two forms, whichever is not the default.
2191 The following options control the amount and kinds of warnings produced
2192 by GCC; for further, language-specific options also refer to
2193 @ref{C++ Dialect Options} and @ref{Objective-C and Objective-C++ Dialect
2197 @cindex syntax checking
2199 @opindex fsyntax-only
2200 Check the code for syntax errors, but don't do anything beyond that.
2204 Issue all the warnings demanded by strict ISO C and ISO C++;
2205 reject all programs that use forbidden extensions, and some other
2206 programs that do not follow ISO C and ISO C++. For ISO C, follows the
2207 version of the ISO C standard specified by any @option{-std} option used.
2209 Valid ISO C and ISO C++ programs should compile properly with or without
2210 this option (though a rare few will require @option{-ansi} or a
2211 @option{-std} option specifying the required version of ISO C)@. However,
2212 without this option, certain GNU extensions and traditional C and C++
2213 features are supported as well. With this option, they are rejected.
2215 @option{-pedantic} does not cause warning messages for use of the
2216 alternate keywords whose names begin and end with @samp{__}. Pedantic
2217 warnings are also disabled in the expression that follows
2218 @code{__extension__}. However, only system header files should use
2219 these escape routes; application programs should avoid them.
2220 @xref{Alternate Keywords}.
2222 Some users try to use @option{-pedantic} to check programs for strict ISO
2223 C conformance. They soon find that it does not do quite what they want:
2224 it finds some non-ISO practices, but not all---only those for which
2225 ISO C @emph{requires} a diagnostic, and some others for which
2226 diagnostics have been added.
2228 A feature to report any failure to conform to ISO C might be useful in
2229 some instances, but would require considerable additional work and would
2230 be quite different from @option{-pedantic}. We don't have plans to
2231 support such a feature in the near future.
2233 Where the standard specified with @option{-std} represents a GNU
2234 extended dialect of C, such as @samp{gnu89} or @samp{gnu99}, there is a
2235 corresponding @dfn{base standard}, the version of ISO C on which the GNU
2236 extended dialect is based. Warnings from @option{-pedantic} are given
2237 where they are required by the base standard. (It would not make sense
2238 for such warnings to be given only for features not in the specified GNU
2239 C dialect, since by definition the GNU dialects of C include all
2240 features the compiler supports with the given option, and there would be
2241 nothing to warn about.)
2243 @item -pedantic-errors
2244 @opindex pedantic-errors
2245 Like @option{-pedantic}, except that errors are produced rather than
2250 Inhibit all warning messages.
2254 Inhibit warning messages about the use of @samp{#import}.
2256 @item -Wchar-subscripts
2257 @opindex Wchar-subscripts
2258 Warn if an array subscript has type @code{char}. This is a common cause
2259 of error, as programmers often forget that this type is signed on some
2261 This warning is enabled by @option{-Wall}.
2265 Warn whenever a comment-start sequence @samp{/*} appears in a @samp{/*}
2266 comment, or whenever a Backslash-Newline appears in a @samp{//} comment.
2267 This warning is enabled by @option{-Wall}.
2269 @item -Wfatal-errors
2270 @opindex Wfatal-errors
2271 This option causes the compiler to abort compilation on the first error
2272 occurred rather than trying to keep going and printing further error
2277 @opindex ffreestanding
2278 @opindex fno-builtin
2279 Check calls to @code{printf} and @code{scanf}, etc., to make sure that
2280 the arguments supplied have types appropriate to the format string
2281 specified, and that the conversions specified in the format string make
2282 sense. This includes standard functions, and others specified by format
2283 attributes (@pxref{Function Attributes}), in the @code{printf},
2284 @code{scanf}, @code{strftime} and @code{strfmon} (an X/Open extension,
2285 not in the C standard) families (or other target-specific families).
2286 Which functions are checked without format attributes having been
2287 specified depends on the standard version selected, and such checks of
2288 functions without the attribute specified are disabled by
2289 @option{-ffreestanding} or @option{-fno-builtin}.
2291 The formats are checked against the format features supported by GNU
2292 libc version 2.2. These include all ISO C90 and C99 features, as well
2293 as features from the Single Unix Specification and some BSD and GNU
2294 extensions. Other library implementations may not support all these
2295 features; GCC does not support warning about features that go beyond a
2296 particular library's limitations. However, if @option{-pedantic} is used
2297 with @option{-Wformat}, warnings will be given about format features not
2298 in the selected standard version (but not for @code{strfmon} formats,
2299 since those are not in any version of the C standard). @xref{C Dialect
2300 Options,,Options Controlling C Dialect}.
2302 Since @option{-Wformat} also checks for null format arguments for
2303 several functions, @option{-Wformat} also implies @option{-Wnonnull}.
2305 @option{-Wformat} is included in @option{-Wall}. For more control over some
2306 aspects of format checking, the options @option{-Wformat-y2k},
2307 @option{-Wno-format-extra-args}, @option{-Wno-format-zero-length},
2308 @option{-Wformat-nonliteral}, @option{-Wformat-security}, and
2309 @option{-Wformat=2} are available, but are not included in @option{-Wall}.
2312 @opindex Wformat-y2k
2313 If @option{-Wformat} is specified, also warn about @code{strftime}
2314 formats which may yield only a two-digit year.
2316 @item -Wno-format-extra-args
2317 @opindex Wno-format-extra-args
2318 If @option{-Wformat} is specified, do not warn about excess arguments to a
2319 @code{printf} or @code{scanf} format function. The C standard specifies
2320 that such arguments are ignored.
2322 Where the unused arguments lie between used arguments that are
2323 specified with @samp{$} operand number specifications, normally
2324 warnings are still given, since the implementation could not know what
2325 type to pass to @code{va_arg} to skip the unused arguments. However,
2326 in the case of @code{scanf} formats, this option will suppress the
2327 warning if the unused arguments are all pointers, since the Single
2328 Unix Specification says that such unused arguments are allowed.
2330 @item -Wno-format-zero-length
2331 @opindex Wno-format-zero-length
2332 If @option{-Wformat} is specified, do not warn about zero-length formats.
2333 The C standard specifies that zero-length formats are allowed.
2335 @item -Wformat-nonliteral
2336 @opindex Wformat-nonliteral
2337 If @option{-Wformat} is specified, also warn if the format string is not a
2338 string literal and so cannot be checked, unless the format function
2339 takes its format arguments as a @code{va_list}.
2341 @item -Wformat-security
2342 @opindex Wformat-security
2343 If @option{-Wformat} is specified, also warn about uses of format
2344 functions that represent possible security problems. At present, this
2345 warns about calls to @code{printf} and @code{scanf} functions where the
2346 format string is not a string literal and there are no format arguments,
2347 as in @code{printf (foo);}. This may be a security hole if the format
2348 string came from untrusted input and contains @samp{%n}. (This is
2349 currently a subset of what @option{-Wformat-nonliteral} warns about, but
2350 in future warnings may be added to @option{-Wformat-security} that are not
2351 included in @option{-Wformat-nonliteral}.)
2355 Enable @option{-Wformat} plus format checks not included in
2356 @option{-Wformat}. Currently equivalent to @samp{-Wformat
2357 -Wformat-nonliteral -Wformat-security -Wformat-y2k}.
2361 Warn about passing a null pointer for arguments marked as
2362 requiring a non-null value by the @code{nonnull} function attribute.
2364 @option{-Wnonnull} is included in @option{-Wall} and @option{-Wformat}. It
2365 can be disabled with the @option{-Wno-nonnull} option.
2367 @item -Winit-self @r{(C, C++, Objective-C and Objective-C++ only)}
2369 Warn about uninitialized variables which are initialized with themselves.
2370 Note this option can only be used with the @option{-Wuninitialized} option,
2371 which in turn only works with @option{-O1} and above.
2373 For example, GCC will warn about @code{i} being uninitialized in the
2374 following snippet only when @option{-Winit-self} has been specified:
2385 @item -Wimplicit-int
2386 @opindex Wimplicit-int
2387 Warn when a declaration does not specify a type.
2388 This warning is enabled by @option{-Wall}.
2390 @item -Wimplicit-function-declaration
2391 @itemx -Werror-implicit-function-declaration
2392 @opindex Wimplicit-function-declaration
2393 @opindex Werror-implicit-function-declaration
2394 Give a warning (or error) whenever a function is used before being
2395 declared. The form @option{-Wno-error-implicit-function-declaration}
2397 This warning is enabled by @option{-Wall} (as a warning, not an error).
2401 Same as @option{-Wimplicit-int} and @option{-Wimplicit-function-declaration}.
2402 This warning is enabled by @option{-Wall}.
2406 Warn if the type of @samp{main} is suspicious. @samp{main} should be a
2407 function with external linkage, returning int, taking either zero
2408 arguments, two, or three arguments of appropriate types.
2409 This warning is enabled by @option{-Wall}.
2411 @item -Wmissing-braces
2412 @opindex Wmissing-braces
2413 Warn if an aggregate or union initializer is not fully bracketed. In
2414 the following example, the initializer for @samp{a} is not fully
2415 bracketed, but that for @samp{b} is fully bracketed.
2418 int a[2][2] = @{ 0, 1, 2, 3 @};
2419 int b[2][2] = @{ @{ 0, 1 @}, @{ 2, 3 @} @};
2422 This warning is enabled by @option{-Wall}.
2424 @item -Wmissing-include-dirs @r{(C, C++, Objective-C and Objective-C++ only)}
2425 @opindex Wmissing-include-dirs
2426 Warn if a user-supplied include directory does not exist.
2429 @opindex Wparentheses
2430 Warn if parentheses are omitted in certain contexts, such
2431 as when there is an assignment in a context where a truth value
2432 is expected, or when operators are nested whose precedence people
2433 often get confused about. Only the warning for an assignment used as
2434 a truth value is supported when compiling C++; the other warnings are
2435 only supported when compiling C@.
2437 Also warn if a comparison like @samp{x<=y<=z} appears; this is
2438 equivalent to @samp{(x<=y ? 1 : 0) <= z}, which is a different
2439 interpretation from that of ordinary mathematical notation.
2441 Also warn about constructions where there may be confusion to which
2442 @code{if} statement an @code{else} branch belongs. Here is an example of
2457 In C, every @code{else} branch belongs to the innermost possible @code{if}
2458 statement, which in this example is @code{if (b)}. This is often not
2459 what the programmer expected, as illustrated in the above example by
2460 indentation the programmer chose. When there is the potential for this
2461 confusion, GCC will issue a warning when this flag is specified.
2462 To eliminate the warning, add explicit braces around the innermost
2463 @code{if} statement so there is no way the @code{else} could belong to
2464 the enclosing @code{if}. The resulting code would look like this:
2480 This warning is enabled by @option{-Wall}.
2482 @item -Wsequence-point
2483 @opindex Wsequence-point
2484 Warn about code that may have undefined semantics because of violations
2485 of sequence point rules in the C standard.
2487 The C standard defines the order in which expressions in a C program are
2488 evaluated in terms of @dfn{sequence points}, which represent a partial
2489 ordering between the execution of parts of the program: those executed
2490 before the sequence point, and those executed after it. These occur
2491 after the evaluation of a full expression (one which is not part of a
2492 larger expression), after the evaluation of the first operand of a
2493 @code{&&}, @code{||}, @code{? :} or @code{,} (comma) operator, before a
2494 function is called (but after the evaluation of its arguments and the
2495 expression denoting the called function), and in certain other places.
2496 Other than as expressed by the sequence point rules, the order of
2497 evaluation of subexpressions of an expression is not specified. All
2498 these rules describe only a partial order rather than a total order,
2499 since, for example, if two functions are called within one expression
2500 with no sequence point between them, the order in which the functions
2501 are called is not specified. However, the standards committee have
2502 ruled that function calls do not overlap.
2504 It is not specified when between sequence points modifications to the
2505 values of objects take effect. Programs whose behavior depends on this
2506 have undefined behavior; the C standard specifies that ``Between the
2507 previous and next sequence point an object shall have its stored value
2508 modified at most once by the evaluation of an expression. Furthermore,
2509 the prior value shall be read only to determine the value to be
2510 stored.''. If a program breaks these rules, the results on any
2511 particular implementation are entirely unpredictable.
2513 Examples of code with undefined behavior are @code{a = a++;}, @code{a[n]
2514 = b[n++]} and @code{a[i++] = i;}. Some more complicated cases are not
2515 diagnosed by this option, and it may give an occasional false positive
2516 result, but in general it has been found fairly effective at detecting
2517 this sort of problem in programs.
2519 The present implementation of this option only works for C programs. A
2520 future implementation may also work for C++ programs.
2522 The C standard is worded confusingly, therefore there is some debate
2523 over the precise meaning of the sequence point rules in subtle cases.
2524 Links to discussions of the problem, including proposed formal
2525 definitions, may be found on the GCC readings page, at
2526 @w{@uref{http://gcc.gnu.org/readings.html}}.
2528 This warning is enabled by @option{-Wall}.
2531 @opindex Wreturn-type
2532 Warn whenever a function is defined with a return-type that defaults to
2533 @code{int}. Also warn about any @code{return} statement with no
2534 return-value in a function whose return-type is not @code{void}.
2536 For C, also warn if the return type of a function has a type qualifier
2537 such as @code{const}. Such a type qualifier has no effect, since the
2538 value returned by a function is not an lvalue. ISO C prohibits
2539 qualified @code{void} return types on function definitions, so such
2540 return types always receive a warning even without this option.
2542 For C++, a function without return type always produces a diagnostic
2543 message, even when @option{-Wno-return-type} is specified. The only
2544 exceptions are @samp{main} and functions defined in system headers.
2546 This warning is enabled by @option{-Wall}.
2550 Warn whenever a @code{switch} statement has an index of enumerated type
2551 and lacks a @code{case} for one or more of the named codes of that
2552 enumeration. (The presence of a @code{default} label prevents this
2553 warning.) @code{case} labels outside the enumeration range also
2554 provoke warnings when this option is used.
2555 This warning is enabled by @option{-Wall}.
2557 @item -Wswitch-default
2558 @opindex Wswitch-switch
2559 Warn whenever a @code{switch} statement does not have a @code{default}
2563 @opindex Wswitch-enum
2564 Warn whenever a @code{switch} statement has an index of enumerated type
2565 and lacks a @code{case} for one or more of the named codes of that
2566 enumeration. @code{case} labels outside the enumeration range also
2567 provoke warnings when this option is used.
2571 Warn if any trigraphs are encountered that might change the meaning of
2572 the program (trigraphs within comments are not warned about).
2573 This warning is enabled by @option{-Wall}.
2575 @item -Wunused-function
2576 @opindex Wunused-function
2577 Warn whenever a static function is declared but not defined or a
2578 non\-inline static function is unused.
2579 This warning is enabled by @option{-Wall}.
2581 @item -Wunused-label
2582 @opindex Wunused-label
2583 Warn whenever a label is declared but not used.
2584 This warning is enabled by @option{-Wall}.
2586 To suppress this warning use the @samp{unused} attribute
2587 (@pxref{Variable Attributes}).
2589 @item -Wunused-parameter
2590 @opindex Wunused-parameter
2591 Warn whenever a function parameter is unused aside from its declaration.
2593 To suppress this warning use the @samp{unused} attribute
2594 (@pxref{Variable Attributes}).
2596 @item -Wunused-variable
2597 @opindex Wunused-variable
2598 Warn whenever a local variable or non-constant static variable is unused
2599 aside from its declaration
2600 This warning is enabled by @option{-Wall}.
2602 To suppress this warning use the @samp{unused} attribute
2603 (@pxref{Variable Attributes}).
2605 @item -Wunused-value
2606 @opindex Wunused-value
2607 Warn whenever a statement computes a result that is explicitly not used.
2608 This warning is enabled by @option{-Wall}.
2610 To suppress this warning cast the expression to @samp{void}.
2614 All the above @option{-Wunused} options combined.
2616 In order to get a warning about an unused function parameter, you must
2617 either specify @samp{-Wextra -Wunused} (note that @samp{-Wall} implies
2618 @samp{-Wunused}), or separately specify @option{-Wunused-parameter}.
2620 @item -Wuninitialized
2621 @opindex Wuninitialized
2622 Warn if an automatic variable is used without first being initialized or
2623 if a variable may be clobbered by a @code{setjmp} call.
2625 These warnings are possible only in optimizing compilation,
2626 because they require data flow information that is computed only
2627 when optimizing. If you don't specify @option{-O}, you simply won't
2630 If you want to warn about code which uses the uninitialized value of the
2631 variable in its own initializer, use the @option{-Winit-self} option.
2633 These warnings occur for individual uninitialized or clobbered
2634 elements of structure, union or array variables as well as for
2635 variables which are uninitialized or clobbered as a whole. They do
2636 not occur for variables or elements declared @code{volatile}. Because
2637 these warnings depend on optimization, the exact variables or elements
2638 for which there are warnings will depend on the precise optimization
2639 options and version of GCC used.
2641 Note that there may be no warning about a variable that is used only
2642 to compute a value that itself is never used, because such
2643 computations may be deleted by data flow analysis before the warnings
2646 These warnings are made optional because GCC is not smart
2647 enough to see all the reasons why the code might be correct
2648 despite appearing to have an error. Here is one example of how
2669 If the value of @code{y} is always 1, 2 or 3, then @code{x} is
2670 always initialized, but GCC doesn't know this. Here is
2671 another common case:
2676 if (change_y) save_y = y, y = new_y;
2678 if (change_y) y = save_y;
2683 This has no bug because @code{save_y} is used only if it is set.
2685 @cindex @code{longjmp} warnings
2686 This option also warns when a non-volatile automatic variable might be
2687 changed by a call to @code{longjmp}. These warnings as well are possible
2688 only in optimizing compilation.
2690 The compiler sees only the calls to @code{setjmp}. It cannot know
2691 where @code{longjmp} will be called; in fact, a signal handler could
2692 call it at any point in the code. As a result, you may get a warning
2693 even when there is in fact no problem because @code{longjmp} cannot
2694 in fact be called at the place which would cause a problem.
2696 Some spurious warnings can be avoided if you declare all the functions
2697 you use that never return as @code{noreturn}. @xref{Function
2700 This warning is enabled by @option{-Wall}.
2702 @item -Wunknown-pragmas
2703 @opindex Wunknown-pragmas
2704 @cindex warning for unknown pragmas
2705 @cindex unknown pragmas, warning
2706 @cindex pragmas, warning of unknown
2707 Warn when a #pragma directive is encountered which is not understood by
2708 GCC@. If this command line option is used, warnings will even be issued
2709 for unknown pragmas in system header files. This is not the case if
2710 the warnings were only enabled by the @option{-Wall} command line option.
2713 @opindex Wno-pragmas
2715 Do not warn about misuses of pragmas, such as incorrect parameters,
2716 invalid syntax, or conflicts between pragmas. See also
2717 @samp{-Wunknown-pragmas}.
2719 @item -Wstrict-aliasing
2720 @opindex Wstrict-aliasing
2721 This option is only active when @option{-fstrict-aliasing} is active.
2722 It warns about code which might break the strict aliasing rules that the
2723 compiler is using for optimization. The warning does not catch all
2724 cases, but does attempt to catch the more common pitfalls. It is
2725 included in @option{-Wall}.
2727 @item -Wstrict-aliasing=2
2728 @opindex Wstrict-aliasing=2
2729 This option is only active when @option{-fstrict-aliasing} is active.
2730 It warns about all code which might break the strict aliasing rules that the
2731 compiler is using for optimization. This warning catches all cases, but
2732 it will also give a warning for some ambiguous cases that are safe.
2736 All of the above @samp{-W} options combined. This enables all the
2737 warnings about constructions that some users consider questionable, and
2738 that are easy to avoid (or modify to prevent the warning), even in
2739 conjunction with macros. This also enables some language-specific
2740 warnings described in @ref{C++ Dialect Options} and
2741 @ref{Objective-C and Objective-C++ Dialect Options}.
2744 The following @option{-W@dots{}} options are not implied by @option{-Wall}.
2745 Some of them warn about constructions that users generally do not
2746 consider questionable, but which occasionally you might wish to check
2747 for; others warn about constructions that are necessary or hard to avoid
2748 in some cases, and there is no simple way to modify the code to suppress
2755 (This option used to be called @option{-W}. The older name is still
2756 supported, but the newer name is more descriptive.) Print extra warning
2757 messages for these events:
2761 A function can return either with or without a value. (Falling
2762 off the end of the function body is considered returning without
2763 a value.) For example, this function would evoke such a
2777 An expression-statement or the left-hand side of a comma expression
2778 contains no side effects.
2779 To suppress the warning, cast the unused expression to void.
2780 For example, an expression such as @samp{x[i,j]} will cause a warning,
2781 but @samp{x[(void)i,j]} will not.
2784 An unsigned value is compared against zero with @samp{<} or @samp{>=}.
2787 Storage-class specifiers like @code{static} are not the first things in
2788 a declaration. According to the C Standard, this usage is obsolescent.
2791 If @option{-Wall} or @option{-Wunused} is also specified, warn about unused
2795 A comparison between signed and unsigned values could produce an
2796 incorrect result when the signed value is converted to unsigned.
2797 (But don't warn if @option{-Wno-sign-compare} is also specified.)
2800 An aggregate has an initializer which does not initialize all members.
2801 This warning can be independently controlled by
2802 @option{-Wmissing-field-initializers}.
2805 A function parameter is declared without a type specifier in K&R-style
2813 An empty body occurs in an @samp{if} or @samp{else} statement.
2816 A pointer is compared against integer zero with @samp{<}, @samp{<=},
2817 @samp{>}, or @samp{>=}.
2820 A variable might be changed by @samp{longjmp} or @samp{vfork}.
2823 Any of several floating-point events that often indicate errors, such as
2824 overflow, underflow, loss of precision, etc.
2826 @item @r{(C++ only)}
2827 An enumerator and a non-enumerator both appear in a conditional expression.
2829 @item @r{(C++ only)}
2830 A non-static reference or non-static @samp{const} member appears in a
2831 class without constructors.
2833 @item @r{(C++ only)}
2834 Ambiguous virtual bases.
2836 @item @r{(C++ only)}
2837 Subscripting an array which has been declared @samp{register}.
2839 @item @r{(C++ only)}
2840 Taking the address of a variable which has been declared @samp{register}.
2842 @item @r{(C++ only)}
2843 A base class is not initialized in a derived class' copy constructor.
2846 @item -Wno-div-by-zero
2847 @opindex Wno-div-by-zero
2848 @opindex Wdiv-by-zero
2849 Do not warn about compile-time integer division by zero. Floating point
2850 division by zero is not warned about, as it can be a legitimate way of
2851 obtaining infinities and NaNs.
2853 @item -Wsystem-headers
2854 @opindex Wsystem-headers
2855 @cindex warnings from system headers
2856 @cindex system headers, warnings from
2857 Print warning messages for constructs found in system header files.
2858 Warnings from system headers are normally suppressed, on the assumption
2859 that they usually do not indicate real problems and would only make the
2860 compiler output harder to read. Using this command line option tells
2861 GCC to emit warnings from system headers as if they occurred in user
2862 code. However, note that using @option{-Wall} in conjunction with this
2863 option will @emph{not} warn about unknown pragmas in system
2864 headers---for that, @option{-Wunknown-pragmas} must also be used.
2867 @opindex Wfloat-equal
2868 Warn if floating point values are used in equality comparisons.
2870 The idea behind this is that sometimes it is convenient (for the
2871 programmer) to consider floating-point values as approximations to
2872 infinitely precise real numbers. If you are doing this, then you need
2873 to compute (by analyzing the code, or in some other way) the maximum or
2874 likely maximum error that the computation introduces, and allow for it
2875 when performing comparisons (and when producing output, but that's a
2876 different problem). In particular, instead of testing for equality, you
2877 would check to see whether the two values have ranges that overlap; and
2878 this is done with the relational operators, so equality comparisons are
2881 @item -Wtraditional @r{(C only)}
2882 @opindex Wtraditional
2883 Warn about certain constructs that behave differently in traditional and
2884 ISO C@. Also warn about ISO C constructs that have no traditional C
2885 equivalent, and/or problematic constructs which should be avoided.
2889 Macro parameters that appear within string literals in the macro body.
2890 In traditional C macro replacement takes place within string literals,
2891 but does not in ISO C@.
2894 In traditional C, some preprocessor directives did not exist.
2895 Traditional preprocessors would only consider a line to be a directive
2896 if the @samp{#} appeared in column 1 on the line. Therefore
2897 @option{-Wtraditional} warns about directives that traditional C
2898 understands but would ignore because the @samp{#} does not appear as the
2899 first character on the line. It also suggests you hide directives like
2900 @samp{#pragma} not understood by traditional C by indenting them. Some
2901 traditional implementations would not recognize @samp{#elif}, so it
2902 suggests avoiding it altogether.
2905 A function-like macro that appears without arguments.
2908 The unary plus operator.
2911 The @samp{U} integer constant suffix, or the @samp{F} or @samp{L} floating point
2912 constant suffixes. (Traditional C does support the @samp{L} suffix on integer
2913 constants.) Note, these suffixes appear in macros defined in the system
2914 headers of most modern systems, e.g.@: the @samp{_MIN}/@samp{_MAX} macros in @code{<limits.h>}.
2915 Use of these macros in user code might normally lead to spurious
2916 warnings, however GCC's integrated preprocessor has enough context to
2917 avoid warning in these cases.
2920 A function declared external in one block and then used after the end of
2924 A @code{switch} statement has an operand of type @code{long}.
2927 A non-@code{static} function declaration follows a @code{static} one.
2928 This construct is not accepted by some traditional C compilers.
2931 The ISO type of an integer constant has a different width or
2932 signedness from its traditional type. This warning is only issued if
2933 the base of the constant is ten. I.e.@: hexadecimal or octal values, which
2934 typically represent bit patterns, are not warned about.
2937 Usage of ISO string concatenation is detected.
2940 Initialization of automatic aggregates.
2943 Identifier conflicts with labels. Traditional C lacks a separate
2944 namespace for labels.
2947 Initialization of unions. If the initializer is zero, the warning is
2948 omitted. This is done under the assumption that the zero initializer in
2949 user code appears conditioned on e.g.@: @code{__STDC__} to avoid missing
2950 initializer warnings and relies on default initialization to zero in the
2954 Conversions by prototypes between fixed/floating point values and vice
2955 versa. The absence of these prototypes when compiling with traditional
2956 C would cause serious problems. This is a subset of the possible
2957 conversion warnings, for the full set use @option{-Wconversion}.
2960 Use of ISO C style function definitions. This warning intentionally is
2961 @emph{not} issued for prototype declarations or variadic functions
2962 because these ISO C features will appear in your code when using
2963 libiberty's traditional C compatibility macros, @code{PARAMS} and
2964 @code{VPARAMS}. This warning is also bypassed for nested functions
2965 because that feature is already a GCC extension and thus not relevant to
2966 traditional C compatibility.
2969 @item -Wdeclaration-after-statement @r{(C only)}
2970 @opindex Wdeclaration-after-statement
2971 Warn when a declaration is found after a statement in a block. This
2972 construct, known from C++, was introduced with ISO C99 and is by default
2973 allowed in GCC@. It is not supported by ISO C90 and was not supported by
2974 GCC versions before GCC 3.0. @xref{Mixed Declarations}.
2978 Warn if an undefined identifier is evaluated in an @samp{#if} directive.
2980 @item -Wno-endif-labels
2981 @opindex Wno-endif-labels
2982 @opindex Wendif-labels
2983 Do not warn whenever an @samp{#else} or an @samp{#endif} are followed by text.
2987 Warn whenever a local variable shadows another local variable, parameter or
2988 global variable or whenever a built-in function is shadowed.
2990 @item -Wlarger-than-@var{len}
2991 @opindex Wlarger-than
2992 Warn whenever an object of larger than @var{len} bytes is defined.
2994 @item -Wunsafe-loop-optimizations
2995 @opindex Wunsafe-loop-optimizations
2996 Warn if the loop cannot be optimized because the compiler could not
2997 assume anything on the bounds of the loop indices. With
2998 @option{-funsafe-loop-optimizations} warn if the compiler made
3001 @item -Wpointer-arith
3002 @opindex Wpointer-arith
3003 Warn about anything that depends on the ``size of'' a function type or
3004 of @code{void}. GNU C assigns these types a size of 1, for
3005 convenience in calculations with @code{void *} pointers and pointers
3008 @item -Wbad-function-cast @r{(C only)}
3009 @opindex Wbad-function-cast
3010 Warn whenever a function call is cast to a non-matching type.
3011 For example, warn if @code{int malloc()} is cast to @code{anything *}.
3014 Warn about ISO C constructs that are outside of the common subset of
3015 ISO C and ISO C++, e.g.@: request for implicit conversion from
3016 @code{void *} to a pointer to non-@code{void} type.
3020 Warn whenever a pointer is cast so as to remove a type qualifier from
3021 the target type. For example, warn if a @code{const char *} is cast
3022 to an ordinary @code{char *}.
3025 @opindex Wcast-align
3026 Warn whenever a pointer is cast such that the required alignment of the
3027 target is increased. For example, warn if a @code{char *} is cast to
3028 an @code{int *} on machines where integers can only be accessed at
3029 two- or four-byte boundaries.
3031 @item -Wwrite-strings
3032 @opindex Wwrite-strings
3033 When compiling C, give string constants the type @code{const
3034 char[@var{length}]} so that
3035 copying the address of one into a non-@code{const} @code{char *}
3036 pointer will get a warning; when compiling C++, warn about the
3037 deprecated conversion from string constants to @code{char *}.
3038 These warnings will help you find at
3039 compile time code that can try to write into a string constant, but
3040 only if you have been very careful about using @code{const} in
3041 declarations and prototypes. Otherwise, it will just be a nuisance;
3042 this is why we did not make @option{-Wall} request these warnings.
3045 @opindex Wconversion
3046 Warn if a prototype causes a type conversion that is different from what
3047 would happen to the same argument in the absence of a prototype. This
3048 includes conversions of fixed point to floating and vice versa, and
3049 conversions changing the width or signedness of a fixed point argument
3050 except when the same as the default promotion.
3052 Also, warn if a negative integer constant expression is implicitly
3053 converted to an unsigned type. For example, warn about the assignment
3054 @code{x = -1} if @code{x} is unsigned. But do not warn about explicit
3055 casts like @code{(unsigned) -1}.
3057 @item -Wsign-compare
3058 @opindex Wsign-compare
3059 @cindex warning for comparison of signed and unsigned values
3060 @cindex comparison of signed and unsigned values, warning
3061 @cindex signed and unsigned values, comparison warning
3062 Warn when a comparison between signed and unsigned values could produce
3063 an incorrect result when the signed value is converted to unsigned.
3064 This warning is also enabled by @option{-Wextra}; to get the other warnings
3065 of @option{-Wextra} without this warning, use @samp{-Wextra -Wno-sign-compare}.
3067 @item -Waggregate-return
3068 @opindex Waggregate-return
3069 Warn if any functions that return structures or unions are defined or
3070 called. (In languages where you can return an array, this also elicits
3073 @item -Wno-attributes
3074 @opindex Wno-attributes
3075 @opindex Wattributes
3076 Do not warn if an unexpected @code{__attribute__} is used, such as
3077 unrecognized attributes, function attributes applied to variables,
3078 etc. This will not stop errors for incorrect use of supported
3081 @item -Wstrict-prototypes @r{(C only)}
3082 @opindex Wstrict-prototypes
3083 Warn if a function is declared or defined without specifying the
3084 argument types. (An old-style function definition is permitted without
3085 a warning if preceded by a declaration which specifies the argument
3088 @item -Wold-style-definition @r{(C only)}
3089 @opindex Wold-style-definition
3090 Warn if an old-style function definition is used. A warning is given
3091 even if there is a previous prototype.
3093 @item -Wmissing-prototypes @r{(C only)}
3094 @opindex Wmissing-prototypes
3095 Warn if a global function is defined without a previous prototype
3096 declaration. This warning is issued even if the definition itself
3097 provides a prototype. The aim is to detect global functions that fail
3098 to be declared in header files.
3100 @item -Wmissing-declarations @r{(C only)}
3101 @opindex Wmissing-declarations
3102 Warn if a global function is defined without a previous declaration.
3103 Do so even if the definition itself provides a prototype.
3104 Use this option to detect global functions that are not declared in
3107 @item -Wmissing-field-initializers
3108 @opindex Wmissing-field-initializers
3111 Warn if a structure's initializer has some fields missing. For
3112 example, the following code would cause such a warning, because
3113 @code{x.h} is implicitly zero:
3116 struct s @{ int f, g, h; @};
3117 struct s x = @{ 3, 4 @};
3120 This option does not warn about designated initializers, so the following
3121 modification would not trigger a warning:
3124 struct s @{ int f, g, h; @};
3125 struct s x = @{ .f = 3, .g = 4 @};
3128 This warning is included in @option{-Wextra}. To get other @option{-Wextra}
3129 warnings without this one, use @samp{-Wextra -Wno-missing-field-initializers}.
3131 @item -Wmissing-noreturn
3132 @opindex Wmissing-noreturn
3133 Warn about functions which might be candidates for attribute @code{noreturn}.
3134 Note these are only possible candidates, not absolute ones. Care should
3135 be taken to manually verify functions actually do not ever return before
3136 adding the @code{noreturn} attribute, otherwise subtle code generation
3137 bugs could be introduced. You will not get a warning for @code{main} in
3138 hosted C environments.
3140 @item -Wmissing-format-attribute
3141 @opindex Wmissing-format-attribute
3143 Warn about function pointers which might be candidates for @code{format}
3144 attributes. Note these are only possible candidates, not absolute ones.
3145 GCC will guess that function pointers with @code{format} attributes that
3146 are used in assignment, initialization, parameter passing or return
3147 statements should have a corresponding @code{format} attribute in the
3148 resulting type. I.e.@: the left-hand side of the assignment or
3149 initialization, the type of the parameter variable, or the return type
3150 of the containing function respectively should also have a @code{format}
3151 attribute to avoid the warning.
3153 GCC will also warn about function definitions which might be
3154 candidates for @code{format} attributes. Again, these are only
3155 possible candidates. GCC will guess that @code{format} attributes
3156 might be appropriate for any function that calls a function like
3157 @code{vprintf} or @code{vscanf}, but this might not always be the
3158 case, and some functions for which @code{format} attributes are
3159 appropriate may not be detected.
3161 @item -Wno-multichar
3162 @opindex Wno-multichar
3164 Do not warn if a multicharacter constant (@samp{'FOOF'}) is used.
3165 Usually they indicate a typo in the user's code, as they have
3166 implementation-defined values, and should not be used in portable code.
3168 @item -Wnormalized=<none|id|nfc|nfkc>
3169 @opindex Wnormalized
3172 @cindex character set, input normalization
3173 In ISO C and ISO C++, two identifiers are different if they are
3174 different sequences of characters. However, sometimes when characters
3175 outside the basic ASCII character set are used, you can have two
3176 different character sequences that look the same. To avoid confusion,
3177 the ISO 10646 standard sets out some @dfn{normalization rules} which
3178 when applied ensure that two sequences that look the same are turned into
3179 the same sequence. GCC can warn you if you are using identifiers which
3180 have not been normalized; this option controls that warning.
3182 There are four levels of warning that GCC supports. The default is
3183 @option{-Wnormalized=nfc}, which warns about any identifier which is
3184 not in the ISO 10646 ``C'' normalized form, @dfn{NFC}. NFC is the
3185 recommended form for most uses.
3187 Unfortunately, there are some characters which ISO C and ISO C++ allow
3188 in identifiers that when turned into NFC aren't allowable as
3189 identifiers. That is, there's no way to use these symbols in portable
3190 ISO C or C++ and have all your identifiers in NFC.
3191 @option{-Wnormalized=id} suppresses the warning for these characters.
3192 It is hoped that future versions of the standards involved will correct
3193 this, which is why this option is not the default.
3195 You can switch the warning off for all characters by writing
3196 @option{-Wnormalized=none}. You would only want to do this if you
3197 were using some other normalization scheme (like ``D''), because
3198 otherwise you can easily create bugs that are literally impossible to see.
3200 Some characters in ISO 10646 have distinct meanings but look identical
3201 in some fonts or display methodologies, especially once formatting has
3202 been applied. For instance @code{\u207F}, ``SUPERSCRIPT LATIN SMALL
3203 LETTER N'', will display just like a regular @code{n} which has been
3204 placed in a superscript. ISO 10646 defines the @dfn{NFKC}
3205 normalisation scheme to convert all these into a standard form as
3206 well, and GCC will warn if your code is not in NFKC if you use
3207 @option{-Wnormalized=nfkc}. This warning is comparable to warning
3208 about every identifier that contains the letter O because it might be
3209 confused with the digit 0, and so is not the default, but may be
3210 useful as a local coding convention if the programming environment is
3211 unable to be fixed to display these characters distinctly.
3213 @item -Wno-deprecated-declarations
3214 @opindex Wno-deprecated-declarations
3215 Do not warn about uses of functions, variables, and types marked as
3216 deprecated by using the @code{deprecated} attribute.
3217 (@pxref{Function Attributes}, @pxref{Variable Attributes},
3218 @pxref{Type Attributes}.)
3222 Warn if a structure is given the packed attribute, but the packed
3223 attribute has no effect on the layout or size of the structure.
3224 Such structures may be mis-aligned for little benefit. For
3225 instance, in this code, the variable @code{f.x} in @code{struct bar}
3226 will be misaligned even though @code{struct bar} does not itself
3227 have the packed attribute:
3234 @} __attribute__((packed));
3244 Warn if padding is included in a structure, either to align an element
3245 of the structure or to align the whole structure. Sometimes when this
3246 happens it is possible to rearrange the fields of the structure to
3247 reduce the padding and so make the structure smaller.
3249 @item -Wredundant-decls
3250 @opindex Wredundant-decls
3251 Warn if anything is declared more than once in the same scope, even in
3252 cases where multiple declaration is valid and changes nothing.
3254 @item -Wnested-externs @r{(C only)}
3255 @opindex Wnested-externs
3256 Warn if an @code{extern} declaration is encountered within a function.
3258 @item -Wunreachable-code
3259 @opindex Wunreachable-code
3260 Warn if the compiler detects that code will never be executed.
3262 This option is intended to warn when the compiler detects that at
3263 least a whole line of source code will never be executed, because
3264 some condition is never satisfied or because it is after a
3265 procedure that never returns.
3267 It is possible for this option to produce a warning even though there
3268 are circumstances under which part of the affected line can be executed,
3269 so care should be taken when removing apparently-unreachable code.
3271 For instance, when a function is inlined, a warning may mean that the
3272 line is unreachable in only one inlined copy of the function.
3274 This option is not made part of @option{-Wall} because in a debugging
3275 version of a program there is often substantial code which checks
3276 correct functioning of the program and is, hopefully, unreachable
3277 because the program does work. Another common use of unreachable
3278 code is to provide behavior which is selectable at compile-time.
3282 Warn if a function can not be inlined and it was declared as inline.
3283 Even with this option, the compiler will not warn about failures to
3284 inline functions declared in system headers.
3286 The compiler uses a variety of heuristics to determine whether or not
3287 to inline a function. For example, the compiler takes into account
3288 the size of the function being inlined and the amount of inlining
3289 that has already been done in the current function. Therefore,
3290 seemingly insignificant changes in the source program can cause the
3291 warnings produced by @option{-Winline} to appear or disappear.
3293 @item -Wno-invalid-offsetof @r{(C++ only)}
3294 @opindex Wno-invalid-offsetof
3295 Suppress warnings from applying the @samp{offsetof} macro to a non-POD
3296 type. According to the 1998 ISO C++ standard, applying @samp{offsetof}
3297 to a non-POD type is undefined. In existing C++ implementations,
3298 however, @samp{offsetof} typically gives meaningful results even when
3299 applied to certain kinds of non-POD types. (Such as a simple
3300 @samp{struct} that fails to be a POD type only by virtue of having a
3301 constructor.) This flag is for users who are aware that they are
3302 writing nonportable code and who have deliberately chosen to ignore the
3305 The restrictions on @samp{offsetof} may be relaxed in a future version
3306 of the C++ standard.
3308 @item -Wno-int-to-pointer-cast @r{(C only)}
3309 @opindex Wno-int-to-pointer-cast
3310 Suppress warnings from casts to pointer type of an integer of a
3313 @item -Wno-pointer-to-int-cast @r{(C only)}
3314 @opindex Wno-pointer-to-int-cast
3315 Suppress warnings from casts from a pointer to an integer type of a
3319 @opindex Winvalid-pch
3320 Warn if a precompiled header (@pxref{Precompiled Headers}) is found in
3321 the search path but can't be used.
3325 @opindex Wno-long-long
3326 Warn if @samp{long long} type is used. This is default. To inhibit
3327 the warning messages, use @option{-Wno-long-long}. Flags
3328 @option{-Wlong-long} and @option{-Wno-long-long} are taken into account
3329 only when @option{-pedantic} flag is used.
3331 @item -Wvariadic-macros
3332 @opindex Wvariadic-macros
3333 @opindex Wno-variadic-macros
3334 Warn if variadic macros are used in pedantic ISO C90 mode, or the GNU
3335 alternate syntax when in pedantic ISO C99 mode. This is default.
3336 To inhibit the warning messages, use @option{-Wno-variadic-macros}.
3338 @item -Wdisabled-optimization
3339 @opindex Wdisabled-optimization
3340 Warn if a requested optimization pass is disabled. This warning does
3341 not generally indicate that there is anything wrong with your code; it
3342 merely indicates that GCC's optimizers were unable to handle the code
3343 effectively. Often, the problem is that your code is too big or too
3344 complex; GCC will refuse to optimize programs when the optimization
3345 itself is likely to take inordinate amounts of time.
3347 @item -Wno-pointer-sign
3348 @opindex Wno-pointer-sign
3349 Don't warn for pointer argument passing or assignment with different signedness.
3350 Only useful in the negative form since this warning is enabled by default.
3351 This option is only supported for C and Objective-C@.
3355 Make all warnings into errors.
3358 @node Debugging Options
3359 @section Options for Debugging Your Program or GCC
3360 @cindex options, debugging
3361 @cindex debugging information options
3363 GCC has various special options that are used for debugging
3364 either your program or GCC:
3369 Produce debugging information in the operating system's native format
3370 (stabs, COFF, XCOFF, or DWARF 2)@. GDB can work with this debugging
3373 On most systems that use stabs format, @option{-g} enables use of extra
3374 debugging information that only GDB can use; this extra information
3375 makes debugging work better in GDB but will probably make other debuggers
3377 refuse to read the program. If you want to control for certain whether
3378 to generate the extra information, use @option{-gstabs+}, @option{-gstabs},
3379 @option{-gxcoff+}, @option{-gxcoff}, or @option{-gvms} (see below).
3381 GCC allows you to use @option{-g} with
3382 @option{-O}. The shortcuts taken by optimized code may occasionally
3383 produce surprising results: some variables you declared may not exist
3384 at all; flow of control may briefly move where you did not expect it;
3385 some statements may not be executed because they compute constant
3386 results or their values were already at hand; some statements may
3387 execute in different places because they were moved out of loops.
3389 Nevertheless it proves possible to debug optimized output. This makes
3390 it reasonable to use the optimizer for programs that might have bugs.
3392 The following options are useful when GCC is generated with the
3393 capability for more than one debugging format.
3397 Produce debugging information for use by GDB@. This means to use the
3398 most expressive format available (DWARF 2, stabs, or the native format
3399 if neither of those are supported), including GDB extensions if at all
3404 Produce debugging information in stabs format (if that is supported),
3405 without GDB extensions. This is the format used by DBX on most BSD
3406 systems. On MIPS, Alpha and System V Release 4 systems this option
3407 produces stabs debugging output which is not understood by DBX or SDB@.
3408 On System V Release 4 systems this option requires the GNU assembler.
3410 @item -feliminate-unused-debug-symbols
3411 @opindex feliminate-unused-debug-symbols
3412 Produce debugging information in stabs format (if that is supported),
3413 for only symbols that are actually used.
3417 Produce debugging information in stabs format (if that is supported),
3418 using GNU extensions understood only by the GNU debugger (GDB)@. The
3419 use of these extensions is likely to make other debuggers crash or
3420 refuse to read the program.
3424 Produce debugging information in COFF format (if that is supported).
3425 This is the format used by SDB on most System V systems prior to
3430 Produce debugging information in XCOFF format (if that is supported).
3431 This is the format used by the DBX debugger on IBM RS/6000 systems.
3435 Produce debugging information in XCOFF format (if that is supported),
3436 using GNU extensions understood only by the GNU debugger (GDB)@. The
3437 use of these extensions is likely to make other debuggers crash or
3438 refuse to read the program, and may cause assemblers other than the GNU
3439 assembler (GAS) to fail with an error.
3443 Produce debugging information in DWARF version 2 format (if that is
3444 supported). This is the format used by DBX on IRIX 6. With this
3445 option, GCC uses features of DWARF version 3 when they are useful;
3446 version 3 is upward compatible with version 2, but may still cause
3447 problems for older debuggers.
3451 Produce debugging information in VMS debug format (if that is
3452 supported). This is the format used by DEBUG on VMS systems.
3455 @itemx -ggdb@var{level}
3456 @itemx -gstabs@var{level}
3457 @itemx -gcoff@var{level}
3458 @itemx -gxcoff@var{level}
3459 @itemx -gvms@var{level}
3460 Request debugging information and also use @var{level} to specify how
3461 much information. The default level is 2.
3463 Level 1 produces minimal information, enough for making backtraces in
3464 parts of the program that you don't plan to debug. This includes
3465 descriptions of functions and external variables, but no information
3466 about local variables and no line numbers.
3468 Level 3 includes extra information, such as all the macro definitions
3469 present in the program. Some debuggers support macro expansion when
3470 you use @option{-g3}.
3472 @option{-gdwarf-2} does not accept a concatenated debug level, because
3473 GCC used to support an option @option{-gdwarf} that meant to generate
3474 debug information in version 1 of the DWARF format (which is very
3475 different from version 2), and it would have been too confusing. That
3476 debug format is long obsolete, but the option cannot be changed now.
3477 Instead use an additional @option{-g@var{level}} option to change the
3478 debug level for DWARF2.
3480 @item -feliminate-dwarf2-dups
3481 @opindex feliminate-dwarf2-dups
3482 Compress DWARF2 debugging information by eliminating duplicated
3483 information about each symbol. This option only makes sense when
3484 generating DWARF2 debugging information with @option{-gdwarf-2}.
3486 @cindex @command{prof}
3489 Generate extra code to write profile information suitable for the
3490 analysis program @command{prof}. You must use this option when compiling
3491 the source files you want data about, and you must also use it when
3494 @cindex @command{gprof}
3497 Generate extra code to write profile information suitable for the
3498 analysis program @command{gprof}. You must use this option when compiling
3499 the source files you want data about, and you must also use it when
3504 Makes the compiler print out each function name as it is compiled, and
3505 print some statistics about each pass when it finishes.
3508 @opindex ftime-report
3509 Makes the compiler print some statistics about the time consumed by each
3510 pass when it finishes.
3513 @opindex fmem-report
3514 Makes the compiler print some statistics about permanent memory
3515 allocation when it finishes.
3517 @item -fprofile-arcs
3518 @opindex fprofile-arcs
3519 Add code so that program flow @dfn{arcs} are instrumented. During
3520 execution the program records how many times each branch and call is
3521 executed and how many times it is taken or returns. When the compiled
3522 program exits it saves this data to a file called
3523 @file{@var{auxname}.gcda} for each source file. The data may be used for
3524 profile-directed optimizations (@option{-fbranch-probabilities}), or for
3525 test coverage analysis (@option{-ftest-coverage}). Each object file's
3526 @var{auxname} is generated from the name of the output file, if
3527 explicitly specified and it is not the final executable, otherwise it is
3528 the basename of the source file. In both cases any suffix is removed
3529 (e.g.@: @file{foo.gcda} for input file @file{dir/foo.c}, or
3530 @file{dir/foo.gcda} for output file specified as @option{-o dir/foo.o}).
3531 @xref{Cross-profiling}.
3533 @cindex @command{gcov}
3537 This option is used to compile and link code instrumented for coverage
3538 analysis. The option is a synonym for @option{-fprofile-arcs}
3539 @option{-ftest-coverage} (when compiling) and @option{-lgcov} (when
3540 linking). See the documentation for those options for more details.
3545 Compile the source files with @option{-fprofile-arcs} plus optimization
3546 and code generation options. For test coverage analysis, use the
3547 additional @option{-ftest-coverage} option. You do not need to profile
3548 every source file in a program.
3551 Link your object files with @option{-lgcov} or @option{-fprofile-arcs}
3552 (the latter implies the former).
3555 Run the program on a representative workload to generate the arc profile
3556 information. This may be repeated any number of times. You can run
3557 concurrent instances of your program, and provided that the file system
3558 supports locking, the data files will be correctly updated. Also
3559 @code{fork} calls are detected and correctly handled (double counting
3563 For profile-directed optimizations, compile the source files again with
3564 the same optimization and code generation options plus
3565 @option{-fbranch-probabilities} (@pxref{Optimize Options,,Options that
3566 Control Optimization}).
3569 For test coverage analysis, use @command{gcov} to produce human readable
3570 information from the @file{.gcno} and @file{.gcda} files. Refer to the
3571 @command{gcov} documentation for further information.
3575 With @option{-fprofile-arcs}, for each function of your program GCC
3576 creates a program flow graph, then finds a spanning tree for the graph.
3577 Only arcs that are not on the spanning tree have to be instrumented: the
3578 compiler adds code to count the number of times that these arcs are
3579 executed. When an arc is the only exit or only entrance to a block, the
3580 instrumentation code can be added to the block; otherwise, a new basic
3581 block must be created to hold the instrumentation code.
3584 @item -ftest-coverage
3585 @opindex ftest-coverage
3586 Produce a notes file that the @command{gcov} code-coverage utility
3587 (@pxref{Gcov,, @command{gcov}---a Test Coverage Program}) can use to
3588 show program coverage. Each source file's note file is called
3589 @file{@var{auxname}.gcno}. Refer to the @option{-fprofile-arcs} option
3590 above for a description of @var{auxname} and instructions on how to
3591 generate test coverage data. Coverage data will match the source files
3592 more closely, if you do not optimize.
3594 @item -d@var{letters}
3595 @item -fdump-rtl-@var{pass}
3597 Says to make debugging dumps during compilation at times specified by
3598 @var{letters}. This is used for debugging the RTL-based passes of the
3599 compiler. The file names for most of the dumps are made by appending a
3600 pass number and a word to the @var{dumpname}. @var{dumpname} is generated
3601 from the name of the output file, if explicitly specified and it is not
3602 an executable, otherwise it is the basename of the source file.
3604 Most debug dumps can be enabled either passing a letter to the @option{-d}
3605 option, or with a long @option{-fdump-rtl} switch; here are the possible
3606 letters for use in @var{letters} and @var{pass}, and their meanings:
3611 Annotate the assembler output with miscellaneous debugging information.
3614 @itemx -fdump-rtl-bp
3616 @opindex fdump-rtl-bp
3617 Dump after computing branch probabilities, to @file{@var{file}.09.bp}.
3620 @itemx -fdump-rtl-bbro
3622 @opindex fdump-rtl-bbro
3623 Dump after block reordering, to @file{@var{file}.30.bbro}.
3626 @itemx -fdump-rtl-combine
3628 @opindex fdump-rtl-combine
3629 Dump after instruction combination, to the file @file{@var{file}.17.combine}.
3632 @itemx -fdump-rtl-ce1
3633 @itemx -fdump-rtl-ce2
3635 @opindex fdump-rtl-ce1
3636 @opindex fdump-rtl-ce2
3637 @option{-dC} and @option{-fdump-rtl-ce1} enable dumping after the
3638 first if conversion, to the file @file{@var{file}.11.ce1}. @option{-dC}
3639 and @option{-fdump-rtl-ce2} enable dumping after the second if
3640 conversion, to the file @file{@var{file}.18.ce2}.
3643 @itemx -fdump-rtl-btl
3644 @itemx -fdump-rtl-dbr
3646 @opindex fdump-rtl-btl
3647 @opindex fdump-rtl-dbr
3648 @option{-dd} and @option{-fdump-rtl-btl} enable dumping after branch
3649 target load optimization, to @file{@var{file}.31.btl}. @option{-dd}
3650 and @option{-fdump-rtl-dbr} enable dumping after delayed branch
3651 scheduling, to @file{@var{file}.36.dbr}.
3655 Dump all macro definitions, at the end of preprocessing, in addition to
3659 @itemx -fdump-rtl-ce3
3661 @opindex fdump-rtl-ce3
3662 Dump after the third if conversion, to @file{@var{file}.28.ce3}.
3665 @itemx -fdump-rtl-cfg
3666 @itemx -fdump-rtl-life
3668 @opindex fdump-rtl-cfg
3669 @opindex fdump-rtl-life
3670 @option{-df} and @option{-fdump-rtl-cfg} enable dumping after control
3671 and data flow analysis, to @file{@var{file}.08.cfg}. @option{-df}
3672 and @option{-fdump-rtl-cfg} enable dumping dump after life analysis,
3673 to @file{@var{file}.16.life}.
3676 @itemx -fdump-rtl-greg
3678 @opindex fdump-rtl-greg
3679 Dump after global register allocation, to @file{@var{file}.23.greg}.
3682 @itemx -fdump-rtl-gcse
3683 @itemx -fdump-rtl-bypass
3685 @opindex fdump-rtl-gcse
3686 @opindex fdump-rtl-bypass
3687 @option{-dG} and @option{-fdump-rtl-gcse} enable dumping after GCSE, to
3688 @file{@var{file}.05.gcse}. @option{-dG} and @option{-fdump-rtl-bypass}
3689 enable dumping after jump bypassing and control flow optimizations, to
3690 @file{@var{file}.07.bypass}.
3693 @itemx -fdump-rtl-eh
3695 @opindex fdump-rtl-eh
3696 Dump after finalization of EH handling code, to @file{@var{file}.02.eh}.
3699 @itemx -fdump-rtl-sibling
3701 @opindex fdump-rtl-sibling
3702 Dump after sibling call optimizations, to @file{@var{file}.01.sibling}.
3705 @itemx -fdump-rtl-jump
3707 @opindex fdump-rtl-jump
3708 Dump after the first jump optimization, to @file{@var{file}.03.jump}.
3711 @itemx -fdump-rtl-stack
3713 @opindex fdump-rtl-stack
3714 Dump after conversion from registers to stack, to @file{@var{file}.33.stack}.
3717 @itemx -fdump-rtl-lreg
3719 @opindex fdump-rtl-lreg
3720 Dump after local register allocation, to @file{@var{file}.22.lreg}.
3723 @itemx -fdump-rtl-loop
3724 @itemx -fdump-rtl-loop2
3726 @opindex fdump-rtl-loop
3727 @opindex fdump-rtl-loop2
3728 @option{-dL} and @option{-fdump-rtl-loop} enable dumping after the first
3729 loop optimization pass, to @file{@var{file}.06.loop}. @option{-dL} and
3730 @option{-fdump-rtl-loop2} enable dumping after the second pass, to
3731 @file{@var{file}.13.loop2}.
3734 @itemx -fdump-rtl-sms
3736 @opindex fdump-rtl-sms
3737 Dump after modulo scheduling, to @file{@var{file}.20.sms}.
3740 @itemx -fdump-rtl-mach
3742 @opindex fdump-rtl-mach
3743 Dump after performing the machine dependent reorganization pass, to
3744 @file{@var{file}.35.mach}.
3747 @itemx -fdump-rtl-rnreg
3749 @opindex fdump-rtl-rnreg
3750 Dump after register renumbering, to @file{@var{file}.29.rnreg}.
3753 @itemx -fdump-rtl-regmove
3755 @opindex fdump-rtl-regmove
3756 Dump after the register move pass, to @file{@var{file}.19.regmove}.
3759 @itemx -fdump-rtl-postreload
3761 @opindex fdump-rtl-postreload
3762 Dump after post-reload optimizations, to @file{@var{file}.24.postreload}.
3765 @itemx -fdump-rtl-expand
3767 @opindex fdump-rtl-expand
3768 Dump after RTL generation, to @file{@var{file}.00.expand}.
3771 @itemx -fdump-rtl-sched2
3773 @opindex fdump-rtl-sched2
3774 Dump after the second scheduling pass, to @file{@var{file}.32.sched2}.
3777 @itemx -fdump-rtl-cse
3779 @opindex fdump-rtl-cse
3780 Dump after CSE (including the jump optimization that sometimes follows
3781 CSE), to @file{@var{file}.04.cse}.
3784 @itemx -fdump-rtl-sched
3786 @opindex fdump-rtl-sched
3787 Dump after the first scheduling pass, to @file{@var{file}.21.sched}.
3790 @itemx -fdump-rtl-cse2
3792 @opindex fdump-rtl-cse2
3793 Dump after the second CSE pass (including the jump optimization that
3794 sometimes follows CSE), to @file{@var{file}.15.cse2}.
3797 @itemx -fdump-rtl-tracer
3799 @opindex fdump-rtl-tracer
3800 Dump after running tracer, to @file{@var{file}.12.tracer}.
3803 @itemx -fdump-rtl-vpt
3804 @itemx -fdump-rtl-vartrack
3806 @opindex fdump-rtl-vpt
3807 @opindex fdump-rtl-vartrack
3808 @option{-dV} and @option{-fdump-rtl-vpt} enable dumping after the value
3809 profile transformations, to @file{@var{file}.10.vpt}. @option{-dV}
3810 and @option{-fdump-rtl-vartrack} enable dumping after variable tracking,
3811 to @file{@var{file}.34.vartrack}.
3814 @itemx -fdump-rtl-flow2
3816 @opindex fdump-rtl-flow2
3817 Dump after the second flow pass, to @file{@var{file}.26.flow2}.
3820 @itemx -fdump-rtl-peephole2
3822 @opindex fdump-rtl-peephole2
3823 Dump after the peephole pass, to @file{@var{file}.27.peephole2}.
3826 @itemx -fdump-rtl-web
3828 @opindex fdump-rtl-web
3829 Dump after live range splitting, to @file{@var{file}.14.web}.
3832 @itemx -fdump-rtl-all
3834 @opindex fdump-rtl-all
3835 Produce all the dumps listed above.
3839 Produce a core dump whenever an error occurs.
3843 Print statistics on memory usage, at the end of the run, to
3848 Annotate the assembler output with a comment indicating which
3849 pattern and alternative was used. The length of each instruction is
3854 Dump the RTL in the assembler output as a comment before each instruction.
3855 Also turns on @option{-dp} annotation.
3859 For each of the other indicated dump files (either with @option{-d} or
3860 @option{-fdump-rtl-@var{pass}}), dump a representation of the control flow
3861 graph suitable for viewing with VCG to @file{@var{file}.@var{pass}.vcg}.
3865 Just generate RTL for a function instead of compiling it. Usually used
3866 with @samp{r} (@option{-fdump-rtl-expand}).
3870 Dump debugging information during parsing, to standard error.
3873 @item -fdump-unnumbered
3874 @opindex fdump-unnumbered
3875 When doing debugging dumps (see @option{-d} option above), suppress instruction
3876 numbers and line number note output. This makes it more feasible to
3877 use diff on debugging dumps for compiler invocations with different
3878 options, in particular with and without @option{-g}.
3880 @item -fdump-translation-unit @r{(C++ only)}
3881 @itemx -fdump-translation-unit-@var{options} @r{(C++ only)}
3882 @opindex fdump-translation-unit
3883 Dump a representation of the tree structure for the entire translation
3884 unit to a file. The file name is made by appending @file{.tu} to the
3885 source file name. If the @samp{-@var{options}} form is used, @var{options}
3886 controls the details of the dump as described for the
3887 @option{-fdump-tree} options.
3889 @item -fdump-class-hierarchy @r{(C++ only)}
3890 @itemx -fdump-class-hierarchy-@var{options} @r{(C++ only)}
3891 @opindex fdump-class-hierarchy
3892 Dump a representation of each class's hierarchy and virtual function
3893 table layout to a file. The file name is made by appending @file{.class}
3894 to the source file name. If the @samp{-@var{options}} form is used,
3895 @var{options} controls the details of the dump as described for the
3896 @option{-fdump-tree} options.
3898 @item -fdump-ipa-@var{switch}
3900 Control the dumping at various stages of inter-procedural analysis
3901 language tree to a file. The file name is generated by appending a switch
3902 specific suffix to the source file name. The following dumps are possible:
3906 Enables all inter-procedural analysis dumps; currently the only produced
3907 dump is the @samp{cgraph} dump.
3910 Dumps information about call-graph optimization, unused function removal,
3911 and inlining decisions.
3914 @item -fdump-tree-@var{switch} @r{(C and C++ only)}
3915 @itemx -fdump-tree-@var{switch}-@var{options} @r{(C and C++ only)}
3917 Control the dumping at various stages of processing the intermediate
3918 language tree to a file. The file name is generated by appending a switch
3919 specific suffix to the source file name. If the @samp{-@var{options}}
3920 form is used, @var{options} is a list of @samp{-} separated options that
3921 control the details of the dump. Not all options are applicable to all
3922 dumps, those which are not meaningful will be ignored. The following
3923 options are available
3927 Print the address of each node. Usually this is not meaningful as it
3928 changes according to the environment and source file. Its primary use
3929 is for tying up a dump file with a debug environment.
3931 Inhibit dumping of members of a scope or body of a function merely
3932 because that scope has been reached. Only dump such items when they
3933 are directly reachable by some other path. When dumping pretty-printed
3934 trees, this option inhibits dumping the bodies of control structures.
3936 Print a raw representation of the tree. By default, trees are
3937 pretty-printed into a C-like representation.
3939 Enable more detailed dumps (not honored by every dump option).
3941 Enable dumping various statistics about the pass (not honored by every dump
3944 Enable showing basic block boundaries (disabled in raw dumps).
3946 Enable showing virtual operands for every statement.
3948 Enable showing line numbers for statements.
3950 Enable showing the unique ID (@code{DECL_UID}) for each variable.
3952 Turn on all options, except @option{raw}, @option{slim} and @option{lineno}.
3955 The following tree dumps are possible:
3959 Dump before any tree based optimization, to @file{@var{file}.original}.
3962 Dump after all tree based optimization, to @file{@var{file}.optimized}.
3965 Dump after function inlining, to @file{@var{file}.inlined}.
3968 @opindex fdump-tree-gimple
3969 Dump each function before and after the gimplification pass to a file. The
3970 file name is made by appending @file{.gimple} to the source file name.
3973 @opindex fdump-tree-cfg
3974 Dump the control flow graph of each function to a file. The file name is
3975 made by appending @file{.cfg} to the source file name.
3978 @opindex fdump-tree-vcg
3979 Dump the control flow graph of each function to a file in VCG format. The
3980 file name is made by appending @file{.vcg} to the source file name. Note
3981 that if the file contains more than one function, the generated file cannot
3982 be used directly by VCG@. You will need to cut and paste each function's
3983 graph into its own separate file first.
3986 @opindex fdump-tree-ch
3987 Dump each function after copying loop headers. The file name is made by
3988 appending @file{.ch} to the source file name.
3991 @opindex fdump-tree-ssa
3992 Dump SSA related information to a file. The file name is made by appending
3993 @file{.ssa} to the source file name.
3996 @opindex fdump-tree-salias
3997 Dump structure aliasing variable information to a file. This file name
3998 is made by appending @file{.salias} to the source file name.
4001 @opindex fdump-tree-alias
4002 Dump aliasing information for each function. The file name is made by
4003 appending @file{.alias} to the source file name.
4006 @opindex fdump-tree-ccp
4007 Dump each function after CCP@. The file name is made by appending
4008 @file{.ccp} to the source file name.
4011 @opindex fdump-tree-storeccp
4012 Dump each function after STORE-CCP. The file name is made by appending
4013 @file{.storeccp} to the source file name.
4016 @opindex fdump-tree-pre
4017 Dump trees after partial redundancy elimination. The file name is made
4018 by appending @file{.pre} to the source file name.
4021 @opindex fdump-tree-fre
4022 Dump trees after full redundancy elimination. The file name is made
4023 by appending @file{.fre} to the source file name.
4026 @opindex fdump-tree-copyprop
4027 Dump trees after copy propagation. The file name is made
4028 by appending @file{.copyprop} to the source file name.
4030 @item store_copyprop
4031 @opindex fdump-tree-store_copyprop
4032 Dump trees after store copy-propagation. The file name is made
4033 by appending @file{.store_copyprop} to the source file name.
4036 @opindex fdump-tree-dce
4037 Dump each function after dead code elimination. The file name is made by
4038 appending @file{.dce} to the source file name.
4041 @opindex fdump-tree-mudflap
4042 Dump each function after adding mudflap instrumentation. The file name is
4043 made by appending @file{.mudflap} to the source file name.
4046 @opindex fdump-tree-sra
4047 Dump each function after performing scalar replacement of aggregates. The
4048 file name is made by appending @file{.sra} to the source file name.
4051 @opindex fdump-tree-sink
4052 Dump each function after performing code sinking. The file name is made
4053 by appending @file{.sink} to the source file name.
4056 @opindex fdump-tree-dom
4057 Dump each function after applying dominator tree optimizations. The file
4058 name is made by appending @file{.dom} to the source file name.
4061 @opindex fdump-tree-dse
4062 Dump each function after applying dead store elimination. The file
4063 name is made by appending @file{.dse} to the source file name.
4066 @opindex fdump-tree-phiopt
4067 Dump each function after optimizing PHI nodes into straightline code. The file
4068 name is made by appending @file{.phiopt} to the source file name.
4071 @opindex fdump-tree-forwprop
4072 Dump each function after forward propagating single use variables. The file
4073 name is made by appending @file{.forwprop} to the source file name.
4076 @opindex fdump-tree-copyrename
4077 Dump each function after applying the copy rename optimization. The file
4078 name is made by appending @file{.copyrename} to the source file name.
4081 @opindex fdump-tree-nrv
4082 Dump each function after applying the named return value optimization on
4083 generic trees. The file name is made by appending @file{.nrv} to the source
4087 @opindex fdump-tree-vect
4088 Dump each function after applying vectorization of loops. The file name is
4089 made by appending @file{.vect} to the source file name.
4092 @opindex fdump-tree-vrp
4093 Dump each function after Value Range Propagation (VRP). The file name
4094 is made by appending @file{.vrp} to the source file name.
4097 @opindex fdump-tree-all
4098 Enable all the available tree dumps with the flags provided in this option.
4101 @item -ftree-vectorizer-verbose=@var{n}
4102 @opindex ftree-vectorizer-verbose
4103 This option controls the amount of debugging output the vectorizer prints.
4104 This information is written to standard error, unless @option{-fdump-tree-all}
4105 or @option{-fdump-tree-vect} is specified, in which case it is output to the
4106 usual dump listing file, @file{.vect}.
4108 @item -frandom-seed=@var{string}
4109 @opindex frandom-string
4110 This option provides a seed that GCC uses when it would otherwise use
4111 random numbers. It is used to generate certain symbol names
4112 that have to be different in every compiled file. It is also used to
4113 place unique stamps in coverage data files and the object files that
4114 produce them. You can use the @option{-frandom-seed} option to produce
4115 reproducibly identical object files.
4117 The @var{string} should be different for every file you compile.
4119 @item -fsched-verbose=@var{n}
4120 @opindex fsched-verbose
4121 On targets that use instruction scheduling, this option controls the
4122 amount of debugging output the scheduler prints. This information is
4123 written to standard error, unless @option{-dS} or @option{-dR} is
4124 specified, in which case it is output to the usual dump
4125 listing file, @file{.sched} or @file{.sched2} respectively. However
4126 for @var{n} greater than nine, the output is always printed to standard
4129 For @var{n} greater than zero, @option{-fsched-verbose} outputs the
4130 same information as @option{-dRS}. For @var{n} greater than one, it
4131 also output basic block probabilities, detailed ready list information
4132 and unit/insn info. For @var{n} greater than two, it includes RTL
4133 at abort point, control-flow and regions info. And for @var{n} over
4134 four, @option{-fsched-verbose} also includes dependence info.
4138 Store the usual ``temporary'' intermediate files permanently; place them
4139 in the current directory and name them based on the source file. Thus,
4140 compiling @file{foo.c} with @samp{-c -save-temps} would produce files
4141 @file{foo.i} and @file{foo.s}, as well as @file{foo.o}. This creates a
4142 preprocessed @file{foo.i} output file even though the compiler now
4143 normally uses an integrated preprocessor.
4145 When used in combination with the @option{-x} command line option,
4146 @option{-save-temps} is sensible enough to avoid over writing an
4147 input source file with the same extension as an intermediate file.
4148 The corresponding intermediate file may be obtained by renaming the
4149 source file before using @option{-save-temps}.
4153 Report the CPU time taken by each subprocess in the compilation
4154 sequence. For C source files, this is the compiler proper and assembler
4155 (plus the linker if linking is done). The output looks like this:
4162 The first number on each line is the ``user time'', that is time spent
4163 executing the program itself. The second number is ``system time'',
4164 time spent executing operating system routines on behalf of the program.
4165 Both numbers are in seconds.
4167 @item -fvar-tracking
4168 @opindex fvar-tracking
4169 Run variable tracking pass. It computes where variables are stored at each
4170 position in code. Better debugging information is then generated
4171 (if the debugging information format supports this information).
4173 It is enabled by default when compiling with optimization (@option{-Os},
4174 @option{-O}, @option{-O2}, ...), debugging information (@option{-g}) and
4175 the debug info format supports it.
4177 @item -print-file-name=@var{library}
4178 @opindex print-file-name
4179 Print the full absolute name of the library file @var{library} that
4180 would be used when linking---and don't do anything else. With this
4181 option, GCC does not compile or link anything; it just prints the
4184 @item -print-multi-directory
4185 @opindex print-multi-directory
4186 Print the directory name corresponding to the multilib selected by any
4187 other switches present in the command line. This directory is supposed
4188 to exist in @env{GCC_EXEC_PREFIX}.
4190 @item -print-multi-lib
4191 @opindex print-multi-lib
4192 Print the mapping from multilib directory names to compiler switches
4193 that enable them. The directory name is separated from the switches by
4194 @samp{;}, and each switch starts with an @samp{@@} instead of the
4195 @samp{-}, without spaces between multiple switches. This is supposed to
4196 ease shell-processing.
4198 @item -print-prog-name=@var{program}
4199 @opindex print-prog-name
4200 Like @option{-print-file-name}, but searches for a program such as @samp{cpp}.
4202 @item -print-libgcc-file-name
4203 @opindex print-libgcc-file-name
4204 Same as @option{-print-file-name=libgcc.a}.
4206 This is useful when you use @option{-nostdlib} or @option{-nodefaultlibs}
4207 but you do want to link with @file{libgcc.a}. You can do
4210 gcc -nostdlib @var{files}@dots{} `gcc -print-libgcc-file-name`
4213 @item -print-search-dirs
4214 @opindex print-search-dirs
4215 Print the name of the configured installation directory and a list of
4216 program and library directories @command{gcc} will search---and don't do anything else.
4218 This is useful when @command{gcc} prints the error message
4219 @samp{installation problem, cannot exec cpp0: No such file or directory}.
4220 To resolve this you either need to put @file{cpp0} and the other compiler
4221 components where @command{gcc} expects to find them, or you can set the environment
4222 variable @env{GCC_EXEC_PREFIX} to the directory where you installed them.
4223 Don't forget the trailing @samp{/}.
4224 @xref{Environment Variables}.
4227 @opindex dumpmachine
4228 Print the compiler's target machine (for example,
4229 @samp{i686-pc-linux-gnu})---and don't do anything else.
4232 @opindex dumpversion
4233 Print the compiler version (for example, @samp{3.0})---and don't do
4238 Print the compiler's built-in specs---and don't do anything else. (This
4239 is used when GCC itself is being built.) @xref{Spec Files}.
4241 @item -feliminate-unused-debug-types
4242 @opindex feliminate-unused-debug-types
4243 Normally, when producing DWARF2 output, GCC will emit debugging
4244 information for all types declared in a compilation
4245 unit, regardless of whether or not they are actually used
4246 in that compilation unit. Sometimes this is useful, such as
4247 if, in the debugger, you want to cast a value to a type that is
4248 not actually used in your program (but is declared). More often,
4249 however, this results in a significant amount of wasted space.
4250 With this option, GCC will avoid producing debug symbol output
4251 for types that are nowhere used in the source file being compiled.
4254 @node Optimize Options
4255 @section Options That Control Optimization
4256 @cindex optimize options
4257 @cindex options, optimization
4259 These options control various sorts of optimizations.
4261 Without any optimization option, the compiler's goal is to reduce the
4262 cost of compilation and to make debugging produce the expected
4263 results. Statements are independent: if you stop the program with a
4264 breakpoint between statements, you can then assign a new value to any
4265 variable or change the program counter to any other statement in the
4266 function and get exactly the results you would expect from the source
4269 Turning on optimization flags makes the compiler attempt to improve
4270 the performance and/or code size at the expense of compilation time
4271 and possibly the ability to debug the program.
4273 The compiler performs optimization based on the knowledge it has of
4274 the program. Optimization levels @option{-O2} and above, in
4275 particular, enable @emph{unit-at-a-time} mode, which allows the
4276 compiler to consider information gained from later functions in
4277 the file when compiling a function. Compiling multiple files at
4278 once to a single output file in @emph{unit-at-a-time} mode allows
4279 the compiler to use information gained from all of the files when
4280 compiling each of them.
4282 Not all optimizations are controlled directly by a flag. Only
4283 optimizations that have a flag are listed.
4290 Optimize. Optimizing compilation takes somewhat more time, and a lot
4291 more memory for a large function.
4293 With @option{-O}, the compiler tries to reduce code size and execution
4294 time, without performing any optimizations that take a great deal of
4297 @option{-O} turns on the following optimization flags:
4298 @gccoptlist{-fdefer-pop @gol
4299 -fdelayed-branch @gol
4300 -fguess-branch-probability @gol
4301 -fcprop-registers @gol
4302 -floop-optimize @gol
4303 -fif-conversion @gol
4304 -fif-conversion2 @gol