1 @c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2 @c 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 @c Free Software Foundation, Inc.
4 @c This is part of the GCC manual.
5 @c For copying conditions, see the file gcc.texi.
12 @c man begin COPYRIGHT
13 Copyright @copyright{} 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
14 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
15 Free Software Foundation, Inc.
17 Permission is granted to copy, distribute and/or modify this document
18 under the terms of the GNU Free Documentation License, Version 1.2 or
19 any later version published by the Free Software Foundation; with the
20 Invariant Sections being ``GNU General Public License'' and ``Funding
21 Free Software'', the Front-Cover texts being (a) (see below), and with
22 the Back-Cover Texts being (b) (see below). A copy of the license is
23 included in the gfdl(7) man page.
25 (a) The FSF's Front-Cover Text is:
29 (b) The FSF's Back-Cover Text is:
31 You have freedom to copy and modify this GNU Manual, like GNU
32 software. Copies published by the Free Software Foundation raise
33 funds for GNU development.
35 @c Set file name and title for the man page.
37 @settitle GNU project C and C++ compiler
39 gcc [@option{-c}|@option{-S}|@option{-E}] [@option{-std=}@var{standard}]
40 [@option{-g}] [@option{-pg}] [@option{-O}@var{level}]
41 [@option{-W}@var{warn}@dots{}] [@option{-pedantic}]
42 [@option{-I}@var{dir}@dots{}] [@option{-L}@var{dir}@dots{}]
43 [@option{-D}@var{macro}[=@var{defn}]@dots{}] [@option{-U}@var{macro}]
44 [@option{-f}@var{option}@dots{}] [@option{-m}@var{machine-option}@dots{}]
45 [@option{-o} @var{outfile}] [@@@var{file}] @var{infile}@dots{}
47 Only the most useful options are listed here; see below for the
48 remainder. @samp{g++} accepts mostly the same options as @samp{gcc}.
51 gpl(7), gfdl(7), fsf-funding(7),
52 cpp(1), gcov(1), as(1), ld(1), gdb(1), adb(1), dbx(1), sdb(1)
53 and the Info entries for @file{gcc}, @file{cpp}, @file{as},
54 @file{ld}, @file{binutils} and @file{gdb}.
57 For instructions on reporting bugs, see
61 See the Info entry for @command{gcc}, or
62 @w{@uref{http://gcc.gnu.org/onlinedocs/gcc/Contributors.html}},
63 for contributors to GCC@.
68 @chapter GCC Command Options
69 @cindex GCC command options
70 @cindex command options
71 @cindex options, GCC command
73 @c man begin DESCRIPTION
74 When you invoke GCC, it normally does preprocessing, compilation,
75 assembly and linking. The ``overall options'' allow you to stop this
76 process at an intermediate stage. For example, the @option{-c} option
77 says not to run the linker. Then the output consists of object files
78 output by the assembler.
80 Other options are passed on to one stage of processing. Some options
81 control the preprocessor and others the compiler itself. Yet other
82 options control the assembler and linker; most of these are not
83 documented here, since you rarely need to use any of them.
85 @cindex C compilation options
86 Most of the command line options that you can use with GCC are useful
87 for C programs; when an option is only useful with another language
88 (usually C++), the explanation says so explicitly. If the description
89 for a particular option does not mention a source language, you can use
90 that option with all supported languages.
92 @cindex C++ compilation options
93 @xref{Invoking G++,,Compiling C++ Programs}, for a summary of special
94 options for compiling C++ programs.
96 @cindex grouping options
97 @cindex options, grouping
98 The @command{gcc} program accepts options and file names as operands. Many
99 options have multi-letter names; therefore multiple single-letter options
100 may @emph{not} be grouped: @option{-dr} is very different from @w{@samp{-d
103 @cindex order of options
104 @cindex options, order
105 You can mix options and other arguments. For the most part, the order
106 you use doesn't matter. Order does matter when you use several
107 options of the same kind; for example, if you specify @option{-L} more
108 than once, the directories are searched in the order specified. Also,
109 the placement of the @option{-l} option is significant.
111 Many options have long names starting with @samp{-f} or with
112 @samp{-W}---for example,
113 @option{-fmove-loop-invariants}, @option{-Wformat} and so on. Most of
114 these have both positive and negative forms; the negative form of
115 @option{-ffoo} would be @option{-fno-foo}. This manual documents
116 only one of these two forms, whichever one is not the default.
120 @xref{Option Index}, for an index to GCC's options.
123 * Option Summary:: Brief list of all options, without explanations.
124 * Overall Options:: Controlling the kind of output:
125 an executable, object files, assembler files,
126 or preprocessed source.
127 * Invoking G++:: Compiling C++ programs.
128 * C Dialect Options:: Controlling the variant of C language compiled.
129 * C++ Dialect Options:: Variations on C++.
130 * Objective-C and Objective-C++ Dialect Options:: Variations on Objective-C
132 * Language Independent Options:: Controlling how diagnostics should be
134 * Warning Options:: How picky should the compiler be?
135 * Debugging Options:: Symbol tables, measurements, and debugging dumps.
136 * Optimize Options:: How much optimization?
137 * Preprocessor Options:: Controlling header files and macro definitions.
138 Also, getting dependency information for Make.
139 * Assembler Options:: Passing options to the assembler.
140 * Link Options:: Specifying libraries and so on.
141 * Directory Options:: Where to find header files and libraries.
142 Where to find the compiler executable files.
143 * Spec Files:: How to pass switches to sub-processes.
144 * Target Options:: Running a cross-compiler, or an old version of GCC.
145 * Submodel Options:: Specifying minor hardware or convention variations,
146 such as 68010 vs 68020.
147 * Code Gen Options:: Specifying conventions for function calls, data layout
149 * Environment Variables:: Env vars that affect GCC.
150 * Precompiled Headers:: Compiling a header once, and using it many times.
151 * Running Protoize:: Automatically adding or removing function prototypes.
157 @section Option Summary
159 Here is a summary of all the options, grouped by type. Explanations are
160 in the following sections.
163 @item Overall Options
164 @xref{Overall Options,,Options Controlling the Kind of Output}.
165 @gccoptlist{-c -S -E -o @var{file} -combine -pipe -pass-exit-codes @gol
166 -x @var{language} -v -### --help@r{[}=@var{class}@r{]} --target-help @gol
167 --version @@@var{file}}
169 @item C Language Options
170 @xref{C Dialect Options,,Options Controlling C Dialect}.
171 @gccoptlist{-ansi -std=@var{standard} -fgnu89-inline @gol
172 -aux-info @var{filename} @gol
173 -fno-asm -fno-builtin -fno-builtin-@var{function} @gol
174 -fhosted -ffreestanding -fopenmp -fms-extensions @gol
175 -trigraphs -no-integrated-cpp -traditional -traditional-cpp @gol
176 -fallow-single-precision -fcond-mismatch -flax-vector-conversions @gol
177 -fsigned-bitfields -fsigned-char @gol
178 -funsigned-bitfields -funsigned-char}
180 @item C++ Language Options
181 @xref{C++ Dialect Options,,Options Controlling C++ Dialect}.
182 @gccoptlist{-fabi-version=@var{n} -fno-access-control -fcheck-new @gol
183 -fconserve-space -ffriend-injection @gol
184 -fno-elide-constructors @gol
185 -fno-enforce-eh-specs @gol
186 -ffor-scope -fno-for-scope -fno-gnu-keywords @gol
187 -fno-implicit-templates @gol
188 -fno-implicit-inline-templates @gol
189 -fno-implement-inlines -fms-extensions @gol
190 -fno-nonansi-builtins -fno-operator-names @gol
191 -fno-optional-diags -fpermissive @gol
192 -frepo -fno-rtti -fstats -ftemplate-depth-@var{n} @gol
193 -fno-threadsafe-statics -fuse-cxa-atexit -fno-weak -nostdinc++ @gol
194 -fno-default-inline -fvisibility-inlines-hidden @gol
195 -fvisibility-ms-compat @gol
196 -Wabi -Wctor-dtor-privacy @gol
197 -Wnon-virtual-dtor -Wreorder @gol
198 -Weffc++ -Wno-deprecated -Wstrict-null-sentinel @gol
199 -Wno-non-template-friend -Wold-style-cast @gol
200 -Woverloaded-virtual -Wno-pmf-conversions @gol
203 @item Objective-C and Objective-C++ Language Options
204 @xref{Objective-C and Objective-C++ Dialect Options,,Options Controlling
205 Objective-C and Objective-C++ Dialects}.
206 @gccoptlist{-fconstant-string-class=@var{class-name} @gol
207 -fgnu-runtime -fnext-runtime @gol
208 -fno-nil-receivers @gol
209 -fobjc-call-cxx-cdtors @gol
210 -fobjc-direct-dispatch @gol
211 -fobjc-exceptions @gol
213 -freplace-objc-classes @gol
216 -Wassign-intercept @gol
217 -Wno-protocol -Wselector @gol
218 -Wstrict-selector-match @gol
219 -Wundeclared-selector}
221 @item Language Independent Options
222 @xref{Language Independent Options,,Options to Control Diagnostic Messages Formatting}.
223 @gccoptlist{-fmessage-length=@var{n} @gol
224 -fdiagnostics-show-location=@r{[}once@r{|}every-line@r{]} @gol
225 -fdiagnostics-show-option}
227 @item Warning Options
228 @xref{Warning Options,,Options to Request or Suppress Warnings}.
229 @gccoptlist{-fsyntax-only -pedantic -pedantic-errors @gol
230 -w -Wextra -Wall -Waddress -Waggregate-return -Warray-bounds @gol
231 -Wno-attributes -Wc++-compat -Wc++0x-compat -Wcast-align -Wcast-qual @gol
232 -Wchar-subscripts -Wclobbered -Wcomment @gol
233 -Wconversion -Wcoverage-mismatch -Wno-deprecated-declarations @gol
234 -Wdisabled-optimization -Wno-div-by-zero @gol
235 -Wempty-body -Wno-endif-labels @gol
236 -Werror -Werror=* @gol
237 -Wfatal-errors -Wfloat-equal -Wformat -Wformat=2 @gol
238 -Wno-format-extra-args -Wformat-nonliteral @gol
239 -Wformat-security -Wformat-y2k @gol
240 -Wframe-larger-than=@var{len} -Wignored-qualifiers @gol
241 -Wimplicit -Wimplicit-function-declaration -Wimplicit-int @gol
242 -Wimport -Wno-import -Winit-self -Winline @gol
243 -Wno-int-to-pointer-cast -Wno-invalid-offsetof @gol
244 -Winvalid-pch -Wlarger-than-@var{len} -Wunsafe-loop-optimizations @gol
245 -Wlogical-op -Wlong-long @gol
246 -Wmain -Wmissing-braces -Wmissing-field-initializers @gol
247 -Wmissing-format-attribute -Wmissing-include-dirs @gol
248 -Wmissing-noreturn @gol
249 -Wno-multichar -Wnonnull -Wno-overflow @gol
250 -Woverlength-strings -Wpacked -Wpadded @gol
251 -Wparentheses -Wpointer-arith -Wno-pointer-to-int-cast @gol
252 -Wredundant-decls @gol
253 -Wreturn-type -Wsequence-point -Wshadow @gol
254 -Wsign-compare -Wsign-conversion -Wstack-protector @gol
255 -Wstrict-aliasing -Wstrict-aliasing=n @gol
256 -Wstrict-overflow -Wstrict-overflow=@var{n} @gol
257 -Wswitch -Wswitch-default -Wswitch-enum @gol
258 -Wsystem-headers -Wtrigraphs -Wtype-limits -Wundef -Wuninitialized @gol
259 -Wunknown-pragmas -Wno-pragmas -Wunreachable-code @gol
260 -Wunused -Wunused-function -Wunused-label -Wunused-parameter @gol
261 -Wunused-value -Wunused-variable @gol
262 -Wvariadic-macros -Wvla @gol
263 -Wvolatile-register-var -Wwrite-strings}
265 @item C and Objective-C-only Warning Options
266 @gccoptlist{-Wbad-function-cast -Wmissing-declarations @gol
267 -Wmissing-parameter-type -Wmissing-prototypes -Wnested-externs @gol
268 -Wold-style-declaration -Wold-style-definition @gol
269 -Wstrict-prototypes -Wtraditional -Wtraditional-conversion @gol
270 -Wdeclaration-after-statement -Wpointer-sign}
272 @item Debugging Options
273 @xref{Debugging Options,,Options for Debugging Your Program or GCC}.
274 @gccoptlist{-d@var{letters} -dumpspecs -dumpmachine -dumpversion @gol
275 -fdbg-cnt-list -fdbg-cnt=@var{counter-value-list} @gol
276 -fdump-noaddr -fdump-unnumbered -fdump-translation-unit@r{[}-@var{n}@r{]} @gol
277 -fdump-class-hierarchy@r{[}-@var{n}@r{]} @gol
278 -fdump-ipa-all -fdump-ipa-cgraph -fdump-ipa-inline @gol
280 -fdump-tree-original@r{[}-@var{n}@r{]} @gol
281 -fdump-tree-optimized@r{[}-@var{n}@r{]} @gol
282 -fdump-tree-cfg -fdump-tree-vcg -fdump-tree-alias @gol
284 -fdump-tree-ssa@r{[}-@var{n}@r{]} -fdump-tree-pre@r{[}-@var{n}@r{]} @gol
285 -fdump-tree-ccp@r{[}-@var{n}@r{]} -fdump-tree-dce@r{[}-@var{n}@r{]} @gol
286 -fdump-tree-gimple@r{[}-raw@r{]} -fdump-tree-mudflap@r{[}-@var{n}@r{]} @gol
287 -fdump-tree-dom@r{[}-@var{n}@r{]} @gol
288 -fdump-tree-dse@r{[}-@var{n}@r{]} @gol
289 -fdump-tree-phiopt@r{[}-@var{n}@r{]} @gol
290 -fdump-tree-forwprop@r{[}-@var{n}@r{]} @gol
291 -fdump-tree-copyrename@r{[}-@var{n}@r{]} @gol
292 -fdump-tree-nrv -fdump-tree-vect @gol
293 -fdump-tree-sink @gol
294 -fdump-tree-sra@r{[}-@var{n}@r{]} @gol
295 -fdump-tree-salias @gol
296 -fdump-tree-fre@r{[}-@var{n}@r{]} @gol
297 -fdump-tree-vrp@r{[}-@var{n}@r{]} @gol
298 -ftree-vectorizer-verbose=@var{n} @gol
299 -fdump-tree-storeccp@r{[}-@var{n}@r{]} @gol
300 -feliminate-dwarf2-dups -feliminate-unused-debug-types @gol
301 -feliminate-unused-debug-symbols -femit-class-debug-always @gol
302 -fmem-report -fpre-ipa-mem-report -fpost-ipa-mem-report -fprofile-arcs @gol
303 -frandom-seed=@var{string} -fsched-verbose=@var{n} @gol
304 -ftest-coverage -ftime-report -fvar-tracking @gol
305 -g -g@var{level} -gcoff -gdwarf-2 @gol
306 -ggdb -gstabs -gstabs+ -gvms -gxcoff -gxcoff+ @gol
307 -fno-merge-debug-strings -fdebug-prefix-map=@var{old}=@var{new} @gol
308 -femit-struct-debug-baseonly -femit-struct-debug-reduced @gol
309 -femit-struct-debug-detailed@r{[}=@var{spec-list}@r{]} @gol
310 -p -pg -print-file-name=@var{library} -print-libgcc-file-name @gol
311 -print-multi-directory -print-multi-lib @gol
312 -print-prog-name=@var{program} -print-search-dirs -Q @gol
313 -print-sysroot-headers-suffix @gol
316 @item Optimization Options
317 @xref{Optimize Options,,Options that Control Optimization}.
319 -falign-functions[=@var{n}] -falign-jumps[=@var{n}] @gol
320 -falign-labels[=@var{n}] -falign-loops[=@var{n}] -fassociative-math @gol
321 -fauto-inc-dec -fbranch-probabilities -fbranch-target-load-optimize @gol
322 -fbranch-target-load-optimize2 -fbtr-bb-exclusive -fcaller-saves @gol
323 -fcheck-data-deps -fcprop-registers -fcrossjumping -fcse-follow-jumps @gol
324 -fcse-skip-blocks -fcx-limited-range -fdata-sections -fdce -fdce @gol
325 -fdelayed-branch -fdelete-null-pointer-checks -fdse -fdse @gol
326 -fearly-inlining -fexpensive-optimizations -ffast-math @gol
327 -ffinite-math-only -ffloat-store -fforward-propagate @gol
328 -ffunction-sections -fgcse -fgcse-after-reload -fgcse-las -fgcse-lm @gol
329 -fgcse-sm -fif-conversion -fif-conversion2 -finline-functions @gol
330 -finline-functions-called-once -finline-limit=@var{n} @gol
331 -finline-small-functions -fipa-cp -fipa-marix-reorg -fipa-pta @gol
332 -fipa-pure-const -fipa-reference -fipa-struct-reorg @gol
333 -fipa-type-escape -fivopts -fkeep-inline-functions -fkeep-static-consts @gol
334 -fmerge-all-constants -fmerge-constants -fmodulo-sched @gol
335 -fmodulo-sched-allow-regmoves -fmove-loop-invariants -fmudflap @gol
336 -fmudflapir -fmudflapth -fno-branch-count-reg -fno-default-inline @gol
337 -fno-defer-pop -fno-function-cse -fno-guess-branch-probability @gol
338 -fno-inline -fno-math-errno -fno-peephole -fno-peephole2 @gol
339 -fno-sched-interblock -fno-sched-spec -fno-signed-zeros @gol
340 -fno-toplevel-reorder -fno-trapping-math -fno-zero-initialized-in-bss @gol
341 -fomit-frame-pointer -foptimize-register-move -foptimize-sibling-calls @gol
342 -fpeel-loops -fpredictive-commoning -fprefetch-loop-arrays @gol
343 -fprofile-generate -fprofile-use -fprofile-values -freciprocal-math @gol
344 -fregmove -frename-registers -freorder-blocks @gol
345 -freorder-blocks-and-partition -freorder-functions @gol
346 -frerun-cse-after-loop -freschedule-modulo-scheduled-loops @gol
347 -frounding-math -frtl-abstract-sequences -fsched2-use-superblocks @gol
348 -fsched2-use-traces -fsched-spec-load -fsched-spec-load-dangerous @gol
349 -fsched-stalled-insns-dep[=@var{n}] -fsched-stalled-insns[=@var{n}] @gol
350 -fschedule-insns -fschedule-insns2 -fsection-anchors -fsee @gol
351 -fsignaling-nans -fsingle-precision-constant -fsplit-ivs-in-unroller @gol
352 -fsplit-wide-types -fstack-protector -fstack-protector-all @gol
353 -fstrict-aliasing -fstrict-overflow -fthread-jumps -ftracer -ftree-ccp @gol
354 -ftree-ch -ftree-copy-prop -ftree-copyrename -ftree-dce @gol
355 -ftree-dominator-opts -ftree-dse -ftree-fre -ftree-loop-im @gol
356 -ftree-loop-ivcanon -ftree-loop-linear -ftree-loop-optimize @gol
357 -ftree-parallelize-loops=@var{n} -ftree-pre -ftree-reassoc -ftree-salias @gol
358 -ftree-sink -ftree-sra -ftree-store-ccp -ftree-ter @gol
359 -ftree-vect-loop-version -ftree-vectorize -ftree-vrp -funit-at-a-time @gol
360 -funroll-all-loops -funroll-loops -funsafe-loop-optimizations @gol
361 -funsafe-math-optimizations -funswitch-loops @gol
362 -fvariable-expansion-in-unroller -fvect-cost-model -fvpt -fweb @gol
364 --param @var{name}=@var{value}
365 -O -O0 -O1 -O2 -O3 -Os}
367 @item Preprocessor Options
368 @xref{Preprocessor Options,,Options Controlling the Preprocessor}.
369 @gccoptlist{-A@var{question}=@var{answer} @gol
370 -A-@var{question}@r{[}=@var{answer}@r{]} @gol
371 -C -dD -dI -dM -dN @gol
372 -D@var{macro}@r{[}=@var{defn}@r{]} -E -H @gol
373 -idirafter @var{dir} @gol
374 -include @var{file} -imacros @var{file} @gol
375 -iprefix @var{file} -iwithprefix @var{dir} @gol
376 -iwithprefixbefore @var{dir} -isystem @var{dir} @gol
377 -imultilib @var{dir} -isysroot @var{dir} @gol
378 -M -MM -MF -MG -MP -MQ -MT -nostdinc @gol
379 -P -fworking-directory -remap @gol
380 -trigraphs -undef -U@var{macro} -Wp,@var{option} @gol
381 -Xpreprocessor @var{option}}
383 @item Assembler Option
384 @xref{Assembler Options,,Passing Options to the Assembler}.
385 @gccoptlist{-Wa,@var{option} -Xassembler @var{option}}
388 @xref{Link Options,,Options for Linking}.
389 @gccoptlist{@var{object-file-name} -l@var{library} @gol
390 -nostartfiles -nodefaultlibs -nostdlib -pie -rdynamic @gol
391 -s -static -static-libgcc -shared -shared-libgcc -symbolic @gol
392 -Wl,@var{option} -Xlinker @var{option} @gol
395 @item Directory Options
396 @xref{Directory Options,,Options for Directory Search}.
397 @gccoptlist{-B@var{prefix} -I@var{dir} -iquote@var{dir} -L@var{dir}
398 -specs=@var{file} -I- --sysroot=@var{dir}}
401 @c I wrote this xref this way to avoid overfull hbox. -- rms
402 @xref{Target Options}.
403 @gccoptlist{-V @var{version} -b @var{machine}}
405 @item Machine Dependent Options
406 @xref{Submodel Options,,Hardware Models and Configurations}.
407 @c This list is ordered alphanumerically by subsection name.
408 @c Try and put the significant identifier (CPU or system) first,
409 @c so users have a clue at guessing where the ones they want will be.
412 @gccoptlist{-EB -EL @gol
413 -mmangle-cpu -mcpu=@var{cpu} -mtext=@var{text-section} @gol
414 -mdata=@var{data-section} -mrodata=@var{readonly-data-section}}
417 @gccoptlist{-mapcs-frame -mno-apcs-frame @gol
418 -mabi=@var{name} @gol
419 -mapcs-stack-check -mno-apcs-stack-check @gol
420 -mapcs-float -mno-apcs-float @gol
421 -mapcs-reentrant -mno-apcs-reentrant @gol
422 -msched-prolog -mno-sched-prolog @gol
423 -mlittle-endian -mbig-endian -mwords-little-endian @gol
424 -mfloat-abi=@var{name} -msoft-float -mhard-float -mfpe @gol
425 -mthumb-interwork -mno-thumb-interwork @gol
426 -mcpu=@var{name} -march=@var{name} -mfpu=@var{name} @gol
427 -mstructure-size-boundary=@var{n} @gol
428 -mabort-on-noreturn @gol
429 -mlong-calls -mno-long-calls @gol
430 -msingle-pic-base -mno-single-pic-base @gol
431 -mpic-register=@var{reg} @gol
432 -mnop-fun-dllimport @gol
433 -mcirrus-fix-invalid-insns -mno-cirrus-fix-invalid-insns @gol
434 -mpoke-function-name @gol
436 -mtpcs-frame -mtpcs-leaf-frame @gol
437 -mcaller-super-interworking -mcallee-super-interworking @gol
441 @gccoptlist{-mmcu=@var{mcu} -msize -minit-stack=@var{n} -mno-interrupts @gol
442 -mcall-prologues -mno-tablejump -mtiny-stack -mint8}
444 @emph{Blackfin Options}
445 @gccoptlist{-mcpu=@var{cpu}@r{[}-@var{sirevision}@r{]} @gol
446 -msim -momit-leaf-frame-pointer -mno-omit-leaf-frame-pointer @gol
447 -mspecld-anomaly -mno-specld-anomaly -mcsync-anomaly -mno-csync-anomaly @gol
448 -mlow-64k -mno-low64k -mstack-check-l1 -mid-shared-library @gol
449 -mno-id-shared-library -mshared-library-id=@var{n} @gol
450 -mleaf-id-shared-library -mno-leaf-id-shared-library @gol
451 -msep-data -mno-sep-data -mlong-calls -mno-long-calls @gol
452 -mfast-fp -minline-plt}
455 @gccoptlist{-mcpu=@var{cpu} -march=@var{cpu} -mtune=@var{cpu} @gol
456 -mmax-stack-frame=@var{n} -melinux-stacksize=@var{n} @gol
457 -metrax4 -metrax100 -mpdebug -mcc-init -mno-side-effects @gol
458 -mstack-align -mdata-align -mconst-align @gol
459 -m32-bit -m16-bit -m8-bit -mno-prologue-epilogue -mno-gotplt @gol
460 -melf -maout -melinux -mlinux -sim -sim2 @gol
461 -mmul-bug-workaround -mno-mul-bug-workaround}
464 @gccoptlist{-mmac -mpush-args}
466 @emph{Darwin Options}
467 @gccoptlist{-all_load -allowable_client -arch -arch_errors_fatal @gol
468 -arch_only -bind_at_load -bundle -bundle_loader @gol
469 -client_name -compatibility_version -current_version @gol
471 -dependency-file -dylib_file -dylinker_install_name @gol
472 -dynamic -dynamiclib -exported_symbols_list @gol
473 -filelist -flat_namespace -force_cpusubtype_ALL @gol
474 -force_flat_namespace -headerpad_max_install_names @gol
476 -image_base -init -install_name -keep_private_externs @gol
477 -multi_module -multiply_defined -multiply_defined_unused @gol
478 -noall_load -no_dead_strip_inits_and_terms @gol
479 -nofixprebinding -nomultidefs -noprebind -noseglinkedit @gol
480 -pagezero_size -prebind -prebind_all_twolevel_modules @gol
481 -private_bundle -read_only_relocs -sectalign @gol
482 -sectobjectsymbols -whyload -seg1addr @gol
483 -sectcreate -sectobjectsymbols -sectorder @gol
484 -segaddr -segs_read_only_addr -segs_read_write_addr @gol
485 -seg_addr_table -seg_addr_table_filename -seglinkedit @gol
486 -segprot -segs_read_only_addr -segs_read_write_addr @gol
487 -single_module -static -sub_library -sub_umbrella @gol
488 -twolevel_namespace -umbrella -undefined @gol
489 -unexported_symbols_list -weak_reference_mismatches @gol
490 -whatsloaded -F -gused -gfull -mmacosx-version-min=@var{version} @gol
491 -mkernel -mone-byte-bool}
493 @emph{DEC Alpha Options}
494 @gccoptlist{-mno-fp-regs -msoft-float -malpha-as -mgas @gol
495 -mieee -mieee-with-inexact -mieee-conformant @gol
496 -mfp-trap-mode=@var{mode} -mfp-rounding-mode=@var{mode} @gol
497 -mtrap-precision=@var{mode} -mbuild-constants @gol
498 -mcpu=@var{cpu-type} -mtune=@var{cpu-type} @gol
499 -mbwx -mmax -mfix -mcix @gol
500 -mfloat-vax -mfloat-ieee @gol
501 -mexplicit-relocs -msmall-data -mlarge-data @gol
502 -msmall-text -mlarge-text @gol
503 -mmemory-latency=@var{time}}
505 @emph{DEC Alpha/VMS Options}
506 @gccoptlist{-mvms-return-codes}
509 @gccoptlist{-mgpr-32 -mgpr-64 -mfpr-32 -mfpr-64 @gol
510 -mhard-float -msoft-float @gol
511 -malloc-cc -mfixed-cc -mdword -mno-dword @gol
512 -mdouble -mno-double @gol
513 -mmedia -mno-media -mmuladd -mno-muladd @gol
514 -mfdpic -minline-plt -mgprel-ro -multilib-library-pic @gol
515 -mlinked-fp -mlong-calls -malign-labels @gol
516 -mlibrary-pic -macc-4 -macc-8 @gol
517 -mpack -mno-pack -mno-eflags -mcond-move -mno-cond-move @gol
518 -moptimize-membar -mno-optimize-membar @gol
519 -mscc -mno-scc -mcond-exec -mno-cond-exec @gol
520 -mvliw-branch -mno-vliw-branch @gol
521 -mmulti-cond-exec -mno-multi-cond-exec -mnested-cond-exec @gol
522 -mno-nested-cond-exec -mtomcat-stats @gol
526 @emph{GNU/Linux Options}
527 @gccoptlist{-muclibc}
529 @emph{H8/300 Options}
530 @gccoptlist{-mrelax -mh -ms -mn -mint32 -malign-300}
533 @gccoptlist{-march=@var{architecture-type} @gol
534 -mbig-switch -mdisable-fpregs -mdisable-indexing @gol
535 -mfast-indirect-calls -mgas -mgnu-ld -mhp-ld @gol
536 -mfixed-range=@var{register-range} @gol
537 -mjump-in-delay -mlinker-opt -mlong-calls @gol
538 -mlong-load-store -mno-big-switch -mno-disable-fpregs @gol
539 -mno-disable-indexing -mno-fast-indirect-calls -mno-gas @gol
540 -mno-jump-in-delay -mno-long-load-store @gol
541 -mno-portable-runtime -mno-soft-float @gol
542 -mno-space-regs -msoft-float -mpa-risc-1-0 @gol
543 -mpa-risc-1-1 -mpa-risc-2-0 -mportable-runtime @gol
544 -mschedule=@var{cpu-type} -mspace-regs -msio -mwsio @gol
545 -munix=@var{unix-std} -nolibdld -static -threads}
547 @emph{i386 and x86-64 Options}
548 @gccoptlist{-mtune=@var{cpu-type} -march=@var{cpu-type} @gol
549 -mfpmath=@var{unit} @gol
550 -masm=@var{dialect} -mno-fancy-math-387 @gol
551 -mno-fp-ret-in-387 -msoft-float @gol
552 -mno-wide-multiply -mrtd -malign-double @gol
553 -mpreferred-stack-boundary=@var{num} -mcx16 -msahf -mrecip @gol
554 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -msse4 @gol
555 -msse4a -m3dnow -mpopcnt -mabm -msse5 @gol
556 -mthreads -mno-align-stringops -minline-all-stringops @gol
557 -mpush-args -maccumulate-outgoing-args -m128bit-long-double @gol
558 -m96bit-long-double -mregparm=@var{num} -msseregparm @gol
559 -mveclibabi=@var{type} -mpc32 -mpc64 -mpc80 -mstackrealign @gol
560 -momit-leaf-frame-pointer -mno-red-zone -mno-tls-direct-seg-refs @gol
561 -mcmodel=@var{code-model} @gol
562 -m32 -m64 -mlarge-data-threshold=@var{num} @gol
563 -mfused-madd -mno-fused-madd}
566 @gccoptlist{-mbig-endian -mlittle-endian -mgnu-as -mgnu-ld -mno-pic @gol
567 -mvolatile-asm-stop -mregister-names -mno-sdata @gol
568 -mconstant-gp -mauto-pic -minline-float-divide-min-latency @gol
569 -minline-float-divide-max-throughput @gol
570 -minline-int-divide-min-latency @gol
571 -minline-int-divide-max-throughput @gol
572 -minline-sqrt-min-latency -minline-sqrt-max-throughput @gol
573 -mno-dwarf2-asm -mearly-stop-bits @gol
574 -mfixed-range=@var{register-range} -mtls-size=@var{tls-size} @gol
575 -mtune=@var{cpu-type} -mt -pthread -milp32 -mlp64 @gol
576 -mno-sched-br-data-spec -msched-ar-data-spec -mno-sched-control-spec @gol
577 -msched-br-in-data-spec -msched-ar-in-data-spec -msched-in-control-spec @gol
578 -msched-ldc -mno-sched-control-ldc -mno-sched-spec-verbose @gol
579 -mno-sched-prefer-non-data-spec-insns @gol
580 -mno-sched-prefer-non-control-spec-insns @gol
581 -mno-sched-count-spec-in-critical-path}
583 @emph{M32R/D Options}
584 @gccoptlist{-m32r2 -m32rx -m32r @gol
586 -malign-loops -mno-align-loops @gol
587 -missue-rate=@var{number} @gol
588 -mbranch-cost=@var{number} @gol
589 -mmodel=@var{code-size-model-type} @gol
590 -msdata=@var{sdata-type} @gol
591 -mno-flush-func -mflush-func=@var{name} @gol
592 -mno-flush-trap -mflush-trap=@var{number} @gol
596 @gccoptlist{-mcpu=@var{cpu} -msim -memregs=@var{number}}
598 @emph{M680x0 Options}
599 @gccoptlist{-march=@var{arch} -mcpu=@var{cpu} -mtune=@var{tune}
600 -m68000 -m68020 -m68020-40 -m68020-60 -m68030 -m68040 @gol
601 -m68060 -mcpu32 -m5200 -m5206e -m528x -m5307 -m5407 @gol
602 -mcfv4e -mbitfield -mno-bitfield -mc68000 -mc68020 @gol
603 -mnobitfield -mrtd -mno-rtd -mdiv -mno-div -mshort @gol
604 -mno-short -mhard-float -m68881 -msoft-float -mpcrel @gol
605 -malign-int -mstrict-align -msep-data -mno-sep-data @gol
606 -mshared-library-id=n -mid-shared-library -mno-id-shared-library}
608 @emph{M68hc1x Options}
609 @gccoptlist{-m6811 -m6812 -m68hc11 -m68hc12 -m68hcs12 @gol
610 -mauto-incdec -minmax -mlong-calls -mshort @gol
611 -msoft-reg-count=@var{count}}
614 @gccoptlist{-mhardlit -mno-hardlit -mdiv -mno-div -mrelax-immediates @gol
615 -mno-relax-immediates -mwide-bitfields -mno-wide-bitfields @gol
616 -m4byte-functions -mno-4byte-functions -mcallgraph-data @gol
617 -mno-callgraph-data -mslow-bytes -mno-slow-bytes -mno-lsim @gol
618 -mlittle-endian -mbig-endian -m210 -m340 -mstack-increment}
621 @gccoptlist{-EL -EB -march=@var{arch} -mtune=@var{arch} @gol
622 -mips1 -mips2 -mips3 -mips4 -mips32 -mips32r2 -mips64 @gol
623 -mips16 -mno-mips16 -mflip-mips16 @gol
624 -minterlink-mips16 -mno-interlink-mips16 @gol
625 -mabi=@var{abi} -mabicalls -mno-abicalls @gol
626 -mshared -mno-shared -mxgot -mno-xgot -mgp32 -mgp64 @gol
627 -mfp32 -mfp64 -mhard-float -msoft-float @gol
628 -msingle-float -mdouble-float -mdsp -mno-dsp -mdspr2 -mno-dspr2 @gol
629 -msmartmips -mno-smartmips @gol
630 -mpaired-single -mno-paired-single -mdmx -mno-mdmx @gol
631 -mips3d -mno-mips3d -mmt -mno-mt -mllsc -mno-llsc @gol
632 -mlong64 -mlong32 -msym32 -mno-sym32 @gol
633 -G@var{num} -mlocal-sdata -mno-local-sdata @gol
634 -mextern-sdata -mno-extern-sdata -mgpopt -mno-gopt @gol
635 -membedded-data -mno-embedded-data @gol
636 -muninit-const-in-rodata -mno-uninit-const-in-rodata @gol
637 -mcode-readable=@var{setting} @gol
638 -msplit-addresses -mno-split-addresses @gol
639 -mexplicit-relocs -mno-explicit-relocs @gol
640 -mcheck-zero-division -mno-check-zero-division @gol
641 -mdivide-traps -mdivide-breaks @gol
642 -mmemcpy -mno-memcpy -mlong-calls -mno-long-calls @gol
643 -mmad -mno-mad -mfused-madd -mno-fused-madd -nocpp @gol
644 -mfix-r4000 -mno-fix-r4000 -mfix-r4400 -mno-fix-r4400 @gol
645 -mfix-vr4120 -mno-fix-vr4120 -mfix-vr4130 -mno-fix-vr4130 @gol
646 -mfix-sb1 -mno-fix-sb1 @gol
647 -mflush-func=@var{func} -mno-flush-func @gol
648 -mbranch-cost=@var{num} -mbranch-likely -mno-branch-likely @gol
649 -mfp-exceptions -mno-fp-exceptions @gol
650 -mvr4130-align -mno-vr4130-align}
653 @gccoptlist{-mlibfuncs -mno-libfuncs -mepsilon -mno-epsilon -mabi=gnu @gol
654 -mabi=mmixware -mzero-extend -mknuthdiv -mtoplevel-symbols @gol
655 -melf -mbranch-predict -mno-branch-predict -mbase-addresses @gol
656 -mno-base-addresses -msingle-exit -mno-single-exit}
658 @emph{MN10300 Options}
659 @gccoptlist{-mmult-bug -mno-mult-bug @gol
660 -mam33 -mno-am33 @gol
661 -mam33-2 -mno-am33-2 @gol
662 -mreturn-pointer-on-d0 @gol
666 @gccoptlist{-mno-crt0 -mbacc -msim @gol
667 -march=@var{cpu-type} }
669 @emph{PDP-11 Options}
670 @gccoptlist{-mfpu -msoft-float -mac0 -mno-ac0 -m40 -m45 -m10 @gol
671 -mbcopy -mbcopy-builtin -mint32 -mno-int16 @gol
672 -mint16 -mno-int32 -mfloat32 -mno-float64 @gol
673 -mfloat64 -mno-float32 -mabshi -mno-abshi @gol
674 -mbranch-expensive -mbranch-cheap @gol
675 -msplit -mno-split -munix-asm -mdec-asm}
677 @emph{PowerPC Options}
678 See RS/6000 and PowerPC Options.
680 @emph{RS/6000 and PowerPC Options}
681 @gccoptlist{-mcpu=@var{cpu-type} @gol
682 -mtune=@var{cpu-type} @gol
683 -mpower -mno-power -mpower2 -mno-power2 @gol
684 -mpowerpc -mpowerpc64 -mno-powerpc @gol
685 -maltivec -mno-altivec @gol
686 -mpowerpc-gpopt -mno-powerpc-gpopt @gol
687 -mpowerpc-gfxopt -mno-powerpc-gfxopt @gol
688 -mmfcrf -mno-mfcrf -mpopcntb -mno-popcntb -mfprnd -mno-fprnd @gol
689 -mcmpb -mno-cmpb -mmfpgpr -mno-mfpgpr -mhard-dfp -mno-hard-dfp @gol
690 -mnew-mnemonics -mold-mnemonics @gol
691 -mfull-toc -mminimal-toc -mno-fp-in-toc -mno-sum-in-toc @gol
692 -m64 -m32 -mxl-compat -mno-xl-compat -mpe @gol
693 -malign-power -malign-natural @gol
694 -msoft-float -mhard-float -mmultiple -mno-multiple @gol
695 -mstring -mno-string -mupdate -mno-update @gol
696 -mfused-madd -mno-fused-madd -mbit-align -mno-bit-align @gol
697 -mstrict-align -mno-strict-align -mrelocatable @gol
698 -mno-relocatable -mrelocatable-lib -mno-relocatable-lib @gol
699 -mtoc -mno-toc -mlittle -mlittle-endian -mbig -mbig-endian @gol
700 -mdynamic-no-pic -maltivec -mswdiv @gol
701 -mprioritize-restricted-insns=@var{priority} @gol
702 -msched-costly-dep=@var{dependence_type} @gol
703 -minsert-sched-nops=@var{scheme} @gol
704 -mcall-sysv -mcall-netbsd @gol
705 -maix-struct-return -msvr4-struct-return @gol
706 -mabi=@var{abi-type} -msecure-plt -mbss-plt @gol
707 -misel -mno-isel @gol
708 -misel=yes -misel=no @gol
710 -mspe=yes -mspe=no @gol
712 -mvrsave -mno-vrsave @gol
713 -mmulhw -mno-mulhw @gol
714 -mdlmzb -mno-dlmzb @gol
715 -mfloat-gprs=yes -mfloat-gprs=no -mfloat-gprs=single -mfloat-gprs=double @gol
716 -mprototype -mno-prototype @gol
717 -msim -mmvme -mads -myellowknife -memb -msdata @gol
718 -msdata=@var{opt} -mvxworks -mwindiss -G @var{num} -pthread}
720 @emph{S/390 and zSeries Options}
721 @gccoptlist{-mtune=@var{cpu-type} -march=@var{cpu-type} @gol
722 -mhard-float -msoft-float -mlong-double-64 -mlong-double-128 @gol
723 -mbackchain -mno-backchain -mpacked-stack -mno-packed-stack @gol
724 -msmall-exec -mno-small-exec -mmvcle -mno-mvcle @gol
725 -m64 -m31 -mdebug -mno-debug -mesa -mzarch @gol
726 -mtpf-trace -mno-tpf-trace -mfused-madd -mno-fused-madd @gol
727 -mwarn-framesize -mwarn-dynamicstack -mstack-size -mstack-guard}
730 @gccoptlist{-meb -mel @gol
734 -mscore5 -mscore5u -mscore7 -mscore7d}
737 @gccoptlist{-m1 -m2 -m2e -m3 -m3e @gol
738 -m4-nofpu -m4-single-only -m4-single -m4 @gol
739 -m4a-nofpu -m4a-single-only -m4a-single -m4a -m4al @gol
740 -m5-64media -m5-64media-nofpu @gol
741 -m5-32media -m5-32media-nofpu @gol
742 -m5-compact -m5-compact-nofpu @gol
743 -mb -ml -mdalign -mrelax @gol
744 -mbigtable -mfmovd -mhitachi -mrenesas -mno-renesas -mnomacsave @gol
745 -mieee -misize -minline-ic_invalidate -mpadstruct -mspace @gol
746 -mprefergot -musermode -multcost=@var{number} -mdiv=@var{strategy} @gol
747 -mdivsi3_libfunc=@var{name} @gol
748 -madjust-unroll -mindexed-addressing -mgettrcost=@var{number} -mpt-fixed @gol
752 @gccoptlist{-mcpu=@var{cpu-type} @gol
753 -mtune=@var{cpu-type} @gol
754 -mcmodel=@var{code-model} @gol
755 -m32 -m64 -mapp-regs -mno-app-regs @gol
756 -mfaster-structs -mno-faster-structs @gol
757 -mfpu -mno-fpu -mhard-float -msoft-float @gol
758 -mhard-quad-float -msoft-quad-float @gol
759 -mimpure-text -mno-impure-text -mlittle-endian @gol
760 -mstack-bias -mno-stack-bias @gol
761 -munaligned-doubles -mno-unaligned-doubles @gol
762 -mv8plus -mno-v8plus -mvis -mno-vis
763 -threads -pthreads -pthread}
766 @gccoptlist{-mwarn-reloc -merror-reloc @gol
767 -msafe-dma -munsafe-dma @gol
769 -msmall-mem -mlarge-mem -mstdmain @gol
770 -mfixed-range=@var{register-range}}
772 @emph{System V Options}
773 @gccoptlist{-Qy -Qn -YP,@var{paths} -Ym,@var{dir}}
776 @gccoptlist{-mlong-calls -mno-long-calls -mep -mno-ep @gol
777 -mprolog-function -mno-prolog-function -mspace @gol
778 -mtda=@var{n} -msda=@var{n} -mzda=@var{n} @gol
779 -mapp-regs -mno-app-regs @gol
780 -mdisable-callt -mno-disable-callt @gol
786 @gccoptlist{-mg -mgnu -munix}
788 @emph{VxWorks Options}
789 @gccoptlist{-mrtp -non-static -Bstatic -Bdynamic @gol
790 -Xbind-lazy -Xbind-now}
792 @emph{x86-64 Options}
793 See i386 and x86-64 Options.
795 @emph{Xstormy16 Options}
798 @emph{Xtensa Options}
799 @gccoptlist{-mconst16 -mno-const16 @gol
800 -mfused-madd -mno-fused-madd @gol
801 -mtext-section-literals -mno-text-section-literals @gol
802 -mtarget-align -mno-target-align @gol
803 -mlongcalls -mno-longcalls}
805 @emph{zSeries Options}
806 See S/390 and zSeries Options.
808 @item Code Generation Options
809 @xref{Code Gen Options,,Options for Code Generation Conventions}.
810 @gccoptlist{-fcall-saved-@var{reg} -fcall-used-@var{reg} @gol
811 -ffixed-@var{reg} -fexceptions @gol
812 -fnon-call-exceptions -funwind-tables @gol
813 -fasynchronous-unwind-tables @gol
814 -finhibit-size-directive -finstrument-functions @gol
815 -finstrument-functions-exclude-function-list=@var{sym},@var{sym},@dots{} @gol
816 -finstrument-functions-exclude-file-list=@var{file},@var{file},@dots{} @gol
817 -fno-common -fno-ident @gol
818 -fpcc-struct-return -fpic -fPIC -fpie -fPIE @gol
819 -fno-jump-tables @gol
820 -frecord-gcc-switches @gol
821 -freg-struct-return -fshort-enums @gol
822 -fshort-double -fshort-wchar @gol
823 -fverbose-asm -fpack-struct[=@var{n}] -fstack-check @gol
824 -fstack-limit-register=@var{reg} -fstack-limit-symbol=@var{sym} @gol
825 -fno-stack-limit -fargument-alias -fargument-noalias @gol
826 -fargument-noalias-global -fargument-noalias-anything @gol
827 -fleading-underscore -ftls-model=@var{model} @gol
828 -ftrapv -fwrapv -fbounds-check @gol
833 * Overall Options:: Controlling the kind of output:
834 an executable, object files, assembler files,
835 or preprocessed source.
836 * C Dialect Options:: Controlling the variant of C language compiled.
837 * C++ Dialect Options:: Variations on C++.
838 * Objective-C and Objective-C++ Dialect Options:: Variations on Objective-C
840 * Language Independent Options:: Controlling how diagnostics should be
842 * Warning Options:: How picky should the compiler be?
843 * Debugging Options:: Symbol tables, measurements, and debugging dumps.
844 * Optimize Options:: How much optimization?
845 * Preprocessor Options:: Controlling header files and macro definitions.
846 Also, getting dependency information for Make.
847 * Assembler Options:: Passing options to the assembler.
848 * Link Options:: Specifying libraries and so on.
849 * Directory Options:: Where to find header files and libraries.
850 Where to find the compiler executable files.
851 * Spec Files:: How to pass switches to sub-processes.
852 * Target Options:: Running a cross-compiler, or an old version of GCC.
855 @node Overall Options
856 @section Options Controlling the Kind of Output
858 Compilation can involve up to four stages: preprocessing, compilation
859 proper, assembly and linking, always in that order. GCC is capable of
860 preprocessing and compiling several files either into several
861 assembler input files, or into one assembler input file; then each
862 assembler input file produces an object file, and linking combines all
863 the object files (those newly compiled, and those specified as input)
864 into an executable file.
866 @cindex file name suffix
867 For any given input file, the file name suffix determines what kind of
872 C source code which must be preprocessed.
875 C source code which should not be preprocessed.
878 C++ source code which should not be preprocessed.
881 Objective-C source code. Note that you must link with the @file{libobjc}
882 library to make an Objective-C program work.
885 Objective-C source code which should not be preprocessed.
889 Objective-C++ source code. Note that you must link with the @file{libobjc}
890 library to make an Objective-C++ program work. Note that @samp{.M} refers
891 to a literal capital M@.
894 Objective-C++ source code which should not be preprocessed.
897 C, C++, Objective-C or Objective-C++ header file to be turned into a
902 @itemx @var{file}.cxx
903 @itemx @var{file}.cpp
904 @itemx @var{file}.CPP
905 @itemx @var{file}.c++
907 C++ source code which must be preprocessed. Note that in @samp{.cxx},
908 the last two letters must both be literally @samp{x}. Likewise,
909 @samp{.C} refers to a literal capital C@.
913 Objective-C++ source code which must be preprocessed.
916 Objective-C++ source code which should not be preprocessed.
921 @itemx @var{file}.hxx
922 @itemx @var{file}.hpp
923 @itemx @var{file}.HPP
924 @itemx @var{file}.h++
925 @itemx @var{file}.tcc
926 C++ header file to be turned into a precompiled header.
929 @itemx @var{file}.for
930 @itemx @var{file}.FOR
931 Fixed form Fortran source code which should not be preprocessed.
934 @itemx @var{file}.fpp
935 @itemx @var{file}.FPP
936 Fixed form Fortran source code which must be preprocessed (with the traditional
940 @itemx @var{file}.f95
941 Free form Fortran source code which should not be preprocessed.
944 @itemx @var{file}.F95
945 Free form Fortran source code which must be preprocessed (with the
946 traditional preprocessor).
948 @c FIXME: Descriptions of Java file types.
955 Ada source code file which contains a library unit declaration (a
956 declaration of a package, subprogram, or generic, or a generic
957 instantiation), or a library unit renaming declaration (a package,
958 generic, or subprogram renaming declaration). Such files are also
961 @itemx @var{file}.adb
962 Ada source code file containing a library unit body (a subprogram or
963 package body). Such files are also called @dfn{bodies}.
965 @c GCC also knows about some suffixes for languages not yet included:
977 Assembler code which must be preprocessed.
980 An object file to be fed straight into linking.
981 Any file name with no recognized suffix is treated this way.
985 You can specify the input language explicitly with the @option{-x} option:
988 @item -x @var{language}
989 Specify explicitly the @var{language} for the following input files
990 (rather than letting the compiler choose a default based on the file
991 name suffix). This option applies to all following input files until
992 the next @option{-x} option. Possible values for @var{language} are:
994 c c-header c-cpp-output
995 c++ c++-header c++-cpp-output
996 objective-c objective-c-header objective-c-cpp-output
997 objective-c++ objective-c++-header objective-c++-cpp-output
998 assembler assembler-with-cpp
1006 Turn off any specification of a language, so that subsequent files are
1007 handled according to their file name suffixes (as they are if @option{-x}
1008 has not been used at all).
1010 @item -pass-exit-codes
1011 @opindex pass-exit-codes
1012 Normally the @command{gcc} program will exit with the code of 1 if any
1013 phase of the compiler returns a non-success return code. If you specify
1014 @option{-pass-exit-codes}, the @command{gcc} program will instead return with
1015 numerically highest error produced by any phase that returned an error
1016 indication. The C, C++, and Fortran frontends return 4, if an internal
1017 compiler error is encountered.
1020 If you only want some of the stages of compilation, you can use
1021 @option{-x} (or filename suffixes) to tell @command{gcc} where to start, and
1022 one of the options @option{-c}, @option{-S}, or @option{-E} to say where
1023 @command{gcc} is to stop. Note that some combinations (for example,
1024 @samp{-x cpp-output -E}) instruct @command{gcc} to do nothing at all.
1029 Compile or assemble the source files, but do not link. The linking
1030 stage simply is not done. The ultimate output is in the form of an
1031 object file for each source file.
1033 By default, the object file name for a source file is made by replacing
1034 the suffix @samp{.c}, @samp{.i}, @samp{.s}, etc., with @samp{.o}.
1036 Unrecognized input files, not requiring compilation or assembly, are
1041 Stop after the stage of compilation proper; do not assemble. The output
1042 is in the form of an assembler code file for each non-assembler input
1045 By default, the assembler file name for a source file is made by
1046 replacing the suffix @samp{.c}, @samp{.i}, etc., with @samp{.s}.
1048 Input files that don't require compilation are ignored.
1052 Stop after the preprocessing stage; do not run the compiler proper. The
1053 output is in the form of preprocessed source code, which is sent to the
1056 Input files which don't require preprocessing are ignored.
1058 @cindex output file option
1061 Place output in file @var{file}. This applies regardless to whatever
1062 sort of output is being produced, whether it be an executable file,
1063 an object file, an assembler file or preprocessed C code.
1065 If @option{-o} is not specified, the default is to put an executable
1066 file in @file{a.out}, the object file for
1067 @file{@var{source}.@var{suffix}} in @file{@var{source}.o}, its
1068 assembler file in @file{@var{source}.s}, a precompiled header file in
1069 @file{@var{source}.@var{suffix}.gch}, and all preprocessed C source on
1074 Print (on standard error output) the commands executed to run the stages
1075 of compilation. Also print the version number of the compiler driver
1076 program and of the preprocessor and the compiler proper.
1080 Like @option{-v} except the commands are not executed and all command
1081 arguments are quoted. This is useful for shell scripts to capture the
1082 driver-generated command lines.
1086 Use pipes rather than temporary files for communication between the
1087 various stages of compilation. This fails to work on some systems where
1088 the assembler is unable to read from a pipe; but the GNU assembler has
1093 If you are compiling multiple source files, this option tells the driver
1094 to pass all the source files to the compiler at once (for those
1095 languages for which the compiler can handle this). This will allow
1096 intermodule analysis (IMA) to be performed by the compiler. Currently the only
1097 language for which this is supported is C@. If you pass source files for
1098 multiple languages to the driver, using this option, the driver will invoke
1099 the compiler(s) that support IMA once each, passing each compiler all the
1100 source files appropriate for it. For those languages that do not support
1101 IMA this option will be ignored, and the compiler will be invoked once for
1102 each source file in that language. If you use this option in conjunction
1103 with @option{-save-temps}, the compiler will generate multiple
1105 (one for each source file), but only one (combined) @file{.o} or
1110 Print (on the standard output) a description of the command line options
1111 understood by @command{gcc}. If the @option{-v} option is also specified
1112 then @option{--help} will also be passed on to the various processes
1113 invoked by @command{gcc}, so that they can display the command line options
1114 they accept. If the @option{-Wextra} option has also been specified
1115 (prior to the @option{--help} option), then command line options which
1116 have no documentation associated with them will also be displayed.
1119 @opindex target-help
1120 Print (on the standard output) a description of target-specific command
1121 line options for each tool. For some targets extra target-specific
1122 information may also be printed.
1124 @item --help=@var{class}@r{[},@var{qualifier}@r{]}
1125 Print (on the standard output) a description of the command line
1126 options understood by the compiler that fit into a specific class.
1127 The class can be one of @samp{optimizers}, @samp{warnings}, @samp{target},
1128 @samp{params}, or @var{language}:
1131 @item @samp{optimizers}
1132 This will display all of the optimization options supported by the
1135 @item @samp{warnings}
1136 This will display all of the options controlling warning messages
1137 produced by the compiler.
1140 This will display target-specific options. Unlike the
1141 @option{--target-help} option however, target-specific options of the
1142 linker and assembler will not be displayed. This is because those
1143 tools do not currently support the extended @option{--help=} syntax.
1146 This will display the values recognized by the @option{--param}
1149 @item @var{language}
1150 This will display the options supported for @var{language}, where
1151 @var{language} is the name of one of the languages supported in this
1155 This will display the options that are common to all languages.
1158 It is possible to further refine the output of the @option{--help=}
1159 option by adding a comma separated list of qualifiers after the
1160 class. These can be any from the following list:
1163 @item @samp{undocumented}
1164 Display only those options which are undocumented.
1167 Display options which take an argument that appears after an equal
1168 sign in the same continuous piece of text, such as:
1169 @samp{--help=target}.
1171 @item @samp{separate}
1172 Display options which take an argument that appears as a separate word
1173 following the original option, such as: @samp{-o output-file}.
1176 Thus for example to display all the undocumented target-specific
1177 switches supported by the compiler the following can be used:
1180 --help=target,undocumented
1183 The sense of a qualifier can be inverted by prefixing it with the
1184 @var{^} character, so for example to display all binary warning
1185 options (i.e., ones that are either on or off and that do not take an
1186 argument), which have a description the following can be used:
1189 --help=warnings,^joined,^undocumented
1192 A class can also be used as a qualifier, although this usually
1193 restricts the output by so much that there is nothing to display. One
1194 case where it does work however is when one of the classes is
1195 @var{target}. So for example to display all the target-specific
1196 optimization options the following can be used:
1199 --help=target,optimizers
1202 The @option{--help=} option can be repeated on the command line. Each
1203 successive use will display its requested class of options, skipping
1204 those that have already been displayed.
1206 If the @option{-Q} option appears on the command line before the
1207 @option{--help=} option, then the descriptive text displayed by
1208 @option{--help=} is changed. Instead of describing the displayed
1209 options, an indication is given as to whether the option is enabled,
1210 disabled or set to a specific value (assuming that the compiler
1211 knows this at the point where the @option{--help=} option is used).
1213 Here is a truncated example from the ARM port of @command{gcc}:
1216 % gcc -Q -mabi=2 --help=target -c
1217 The following options are target specific:
1219 -mabort-on-noreturn [disabled]
1223 The output is sensitive to the effects of previous command line
1224 options, so for example it is possible to find out which optimizations
1225 are enabled at @option{-O2} by using:
1228 -O2 --help=optimizers
1231 Alternatively you can discover which binary optimizations are enabled
1232 by @option{-O3} by using:
1235 gcc -c -Q -O3 --help=optimizers > /tmp/O3-opts
1236 gcc -c -Q -O2 --help=optimizers > /tmp/O2-opts
1237 diff /tmp/O2-opts /tmp/O3-opts | grep enabled
1242 Display the version number and copyrights of the invoked GCC@.
1244 @include @value{srcdir}/../libiberty/at-file.texi
1248 @section Compiling C++ Programs
1250 @cindex suffixes for C++ source
1251 @cindex C++ source file suffixes
1252 C++ source files conventionally use one of the suffixes @samp{.C},
1253 @samp{.cc}, @samp{.cpp}, @samp{.CPP}, @samp{.c++}, @samp{.cp}, or
1254 @samp{.cxx}; C++ header files often use @samp{.hh}, @samp{.hpp},
1255 @samp{.H}, or (for shared template code) @samp{.tcc}; and
1256 preprocessed C++ files use the suffix @samp{.ii}. GCC recognizes
1257 files with these names and compiles them as C++ programs even if you
1258 call the compiler the same way as for compiling C programs (usually
1259 with the name @command{gcc}).
1263 However, the use of @command{gcc} does not add the C++ library.
1264 @command{g++} is a program that calls GCC and treats @samp{.c},
1265 @samp{.h} and @samp{.i} files as C++ source files instead of C source
1266 files unless @option{-x} is used, and automatically specifies linking
1267 against the C++ library. This program is also useful when
1268 precompiling a C header file with a @samp{.h} extension for use in C++
1269 compilations. On many systems, @command{g++} is also installed with
1270 the name @command{c++}.
1272 @cindex invoking @command{g++}
1273 When you compile C++ programs, you may specify many of the same
1274 command-line options that you use for compiling programs in any
1275 language; or command-line options meaningful for C and related
1276 languages; or options that are meaningful only for C++ programs.
1277 @xref{C Dialect Options,,Options Controlling C Dialect}, for
1278 explanations of options for languages related to C@.
1279 @xref{C++ Dialect Options,,Options Controlling C++ Dialect}, for
1280 explanations of options that are meaningful only for C++ programs.
1282 @node C Dialect Options
1283 @section Options Controlling C Dialect
1284 @cindex dialect options
1285 @cindex language dialect options
1286 @cindex options, dialect
1288 The following options control the dialect of C (or languages derived
1289 from C, such as C++, Objective-C and Objective-C++) that the compiler
1293 @cindex ANSI support
1297 In C mode, this is equivalent to @samp{-std=c89}. In C++ mode, it is
1298 equivalent to @samp{-std=c++98}.
1300 This turns off certain features of GCC that are incompatible with ISO
1301 C90 (when compiling C code), or of standard C++ (when compiling C++ code),
1302 such as the @code{asm} and @code{typeof} keywords, and
1303 predefined macros such as @code{unix} and @code{vax} that identify the
1304 type of system you are using. It also enables the undesirable and
1305 rarely used ISO trigraph feature. For the C compiler,
1306 it disables recognition of C++ style @samp{//} comments as well as
1307 the @code{inline} keyword.
1309 The alternate keywords @code{__asm__}, @code{__extension__},
1310 @code{__inline__} and @code{__typeof__} continue to work despite
1311 @option{-ansi}. You would not want to use them in an ISO C program, of
1312 course, but it is useful to put them in header files that might be included
1313 in compilations done with @option{-ansi}. Alternate predefined macros
1314 such as @code{__unix__} and @code{__vax__} are also available, with or
1315 without @option{-ansi}.
1317 The @option{-ansi} option does not cause non-ISO programs to be
1318 rejected gratuitously. For that, @option{-pedantic} is required in
1319 addition to @option{-ansi}. @xref{Warning Options}.
1321 The macro @code{__STRICT_ANSI__} is predefined when the @option{-ansi}
1322 option is used. Some header files may notice this macro and refrain
1323 from declaring certain functions or defining certain macros that the
1324 ISO standard doesn't call for; this is to avoid interfering with any
1325 programs that might use these names for other things.
1327 Functions that would normally be built in but do not have semantics
1328 defined by ISO C (such as @code{alloca} and @code{ffs}) are not built-in
1329 functions when @option{-ansi} is used. @xref{Other Builtins,,Other
1330 built-in functions provided by GCC}, for details of the functions
1335 Determine the language standard. @xref{Standards,,Language Standards
1336 Supported by GCC}, for details of these standard versions. This option
1337 is currently only supported when compiling C or C++.
1339 The compiler can accept several base standards, such as @samp{c89} or
1340 @samp{c++98}, and GNU dialects of those standards, such as
1341 @samp{gnu89} or @samp{gnu++98}. By specifing a base standard, the
1342 compiler will accept all programs following that standard and those
1343 using GNU extensions that do not contradict it. For example,
1344 @samp{-std=c89} turns off certain features of GCC that are
1345 incompatible with ISO C90, such as the @code{asm} and @code{typeof}
1346 keywords, but not other GNU extensions that do not have a meaning in
1347 ISO C90, such as omitting the middle term of a @code{?:}
1348 expression. On the other hand, by specifing a GNU dialect of a
1349 standard, all features the compiler support are enabled, even when
1350 those features change the meaning of the base standard and some
1351 strict-conforming programs may be rejected. The particular standard
1352 is used by @option{-pedantic} to identify which features are GNU
1353 extensions given that version of the standard. For example
1354 @samp{-std=gnu89 -pedantic} would warn about C++ style @samp{//}
1355 comments, while @samp{-std=gnu99 -pedantic} would not.
1357 A value for this option must be provided; possible values are
1362 Support all ISO C90 programs (certain GNU extensions that conflict
1363 with ISO C90 are disabled). Same as @option{-ansi} for C code.
1365 @item iso9899:199409
1366 ISO C90 as modified in amendment 1.
1372 ISO C99. Note that this standard is not yet fully supported; see
1373 @w{@uref{http://gcc.gnu.org/c99status.html}} for more information. The
1374 names @samp{c9x} and @samp{iso9899:199x} are deprecated.
1377 GNU dialect of ISO C90 (including some C99 features). This
1378 is the default for C code.
1382 GNU dialect of ISO C99. When ISO C99 is fully implemented in GCC,
1383 this will become the default. The name @samp{gnu9x} is deprecated.
1386 The 1998 ISO C++ standard plus amendments. Same as @option{-ansi} for
1390 GNU dialect of @option{-std=c++98}. This is the default for
1394 The working draft of the upcoming ISO C++0x standard. This option
1395 enables experimental features that are likely to be included in
1396 C++0x. The working draft is constantly changing, and any feature that is
1397 enabled by this flag may be removed from future versions of GCC if it is
1398 not part of the C++0x standard.
1401 GNU dialect of @option{-std=c++0x}. This option enables
1402 experimental features that may be removed in future versions of GCC.
1405 @item -fgnu89-inline
1406 @opindex fgnu89-inline
1407 The option @option{-fgnu89-inline} tells GCC to use the traditional
1408 GNU semantics for @code{inline} functions when in C99 mode.
1409 @xref{Inline,,An Inline Function is As Fast As a Macro}. This option
1410 is accepted and ignored by GCC versions 4.1.3 up to but not including
1411 4.3. In GCC versions 4.3 and later it changes the behavior of GCC in
1412 C99 mode. Using this option is roughly equivalent to adding the
1413 @code{gnu_inline} function attribute to all inline functions
1414 (@pxref{Function Attributes}).
1416 The option @option{-fno-gnu89-inline} explicitly tells GCC to use the
1417 C99 semantics for @code{inline} when in C99 or gnu99 mode (i.e., it
1418 specifies the default behavior). This option was first supported in
1419 GCC 4.3. This option is not supported in C89 or gnu89 mode.
1421 The preprocessor macros @code{__GNUC_GNU_INLINE__} and
1422 @code{__GNUC_STDC_INLINE__} may be used to check which semantics are
1423 in effect for @code{inline} functions. @xref{Common Predefined
1424 Macros,,,cpp,The C Preprocessor}.
1426 @item -aux-info @var{filename}
1428 Output to the given filename prototyped declarations for all functions
1429 declared and/or defined in a translation unit, including those in header
1430 files. This option is silently ignored in any language other than C@.
1432 Besides declarations, the file indicates, in comments, the origin of
1433 each declaration (source file and line), whether the declaration was
1434 implicit, prototyped or unprototyped (@samp{I}, @samp{N} for new or
1435 @samp{O} for old, respectively, in the first character after the line
1436 number and the colon), and whether it came from a declaration or a
1437 definition (@samp{C} or @samp{F}, respectively, in the following
1438 character). In the case of function definitions, a K&R-style list of
1439 arguments followed by their declarations is also provided, inside
1440 comments, after the declaration.
1444 Do not recognize @code{asm}, @code{inline} or @code{typeof} as a
1445 keyword, so that code can use these words as identifiers. You can use
1446 the keywords @code{__asm__}, @code{__inline__} and @code{__typeof__}
1447 instead. @option{-ansi} implies @option{-fno-asm}.
1449 In C++, this switch only affects the @code{typeof} keyword, since
1450 @code{asm} and @code{inline} are standard keywords. You may want to
1451 use the @option{-fno-gnu-keywords} flag instead, which has the same
1452 effect. In C99 mode (@option{-std=c99} or @option{-std=gnu99}), this
1453 switch only affects the @code{asm} and @code{typeof} keywords, since
1454 @code{inline} is a standard keyword in ISO C99.
1457 @itemx -fno-builtin-@var{function}
1458 @opindex fno-builtin
1459 @cindex built-in functions
1460 Don't recognize built-in functions that do not begin with
1461 @samp{__builtin_} as prefix. @xref{Other Builtins,,Other built-in
1462 functions provided by GCC}, for details of the functions affected,
1463 including those which are not built-in functions when @option{-ansi} or
1464 @option{-std} options for strict ISO C conformance are used because they
1465 do not have an ISO standard meaning.
1467 GCC normally generates special code to handle certain built-in functions
1468 more efficiently; for instance, calls to @code{alloca} may become single
1469 instructions that adjust the stack directly, and calls to @code{memcpy}
1470 may become inline copy loops. The resulting code is often both smaller
1471 and faster, but since the function calls no longer appear as such, you
1472 cannot set a breakpoint on those calls, nor can you change the behavior
1473 of the functions by linking with a different library. In addition,
1474 when a function is recognized as a built-in function, GCC may use
1475 information about that function to warn about problems with calls to
1476 that function, or to generate more efficient code, even if the
1477 resulting code still contains calls to that function. For example,
1478 warnings are given with @option{-Wformat} for bad calls to
1479 @code{printf}, when @code{printf} is built in, and @code{strlen} is
1480 known not to modify global memory.
1482 With the @option{-fno-builtin-@var{function}} option
1483 only the built-in function @var{function} is
1484 disabled. @var{function} must not begin with @samp{__builtin_}. If a
1485 function is named this is not built-in in this version of GCC, this
1486 option is ignored. There is no corresponding
1487 @option{-fbuiltin-@var{function}} option; if you wish to enable
1488 built-in functions selectively when using @option{-fno-builtin} or
1489 @option{-ffreestanding}, you may define macros such as:
1492 #define abs(n) __builtin_abs ((n))
1493 #define strcpy(d, s) __builtin_strcpy ((d), (s))
1498 @cindex hosted environment
1500 Assert that compilation takes place in a hosted environment. This implies
1501 @option{-fbuiltin}. A hosted environment is one in which the
1502 entire standard library is available, and in which @code{main} has a return
1503 type of @code{int}. Examples are nearly everything except a kernel.
1504 This is equivalent to @option{-fno-freestanding}.
1506 @item -ffreestanding
1507 @opindex ffreestanding
1508 @cindex hosted environment
1510 Assert that compilation takes place in a freestanding environment. This
1511 implies @option{-fno-builtin}. A freestanding environment
1512 is one in which the standard library may not exist, and program startup may
1513 not necessarily be at @code{main}. The most obvious example is an OS kernel.
1514 This is equivalent to @option{-fno-hosted}.
1516 @xref{Standards,,Language Standards Supported by GCC}, for details of
1517 freestanding and hosted environments.
1521 @cindex openmp parallel
1522 Enable handling of OpenMP directives @code{#pragma omp} in C/C++ and
1523 @code{!$omp} in Fortran. When @option{-fopenmp} is specified, the
1524 compiler generates parallel code according to the OpenMP Application
1525 Program Interface v2.5 @w{@uref{http://www.openmp.org/}}. This option
1526 implies @option{-pthread}, and thus is only supported on targets that
1527 have support for @option{-pthread}.
1529 @item -fms-extensions
1530 @opindex fms-extensions
1531 Accept some non-standard constructs used in Microsoft header files.
1533 Some cases of unnamed fields in structures and unions are only
1534 accepted with this option. @xref{Unnamed Fields,,Unnamed struct/union
1535 fields within structs/unions}, for details.
1539 Support ISO C trigraphs. The @option{-ansi} option (and @option{-std}
1540 options for strict ISO C conformance) implies @option{-trigraphs}.
1542 @item -no-integrated-cpp
1543 @opindex no-integrated-cpp
1544 Performs a compilation in two passes: preprocessing and compiling. This
1545 option allows a user supplied "cc1", "cc1plus", or "cc1obj" via the
1546 @option{-B} option. The user supplied compilation step can then add in
1547 an additional preprocessing step after normal preprocessing but before
1548 compiling. The default is to use the integrated cpp (internal cpp)
1550 The semantics of this option will change if "cc1", "cc1plus", and
1551 "cc1obj" are merged.
1553 @cindex traditional C language
1554 @cindex C language, traditional
1556 @itemx -traditional-cpp
1557 @opindex traditional-cpp
1558 @opindex traditional
1559 Formerly, these options caused GCC to attempt to emulate a pre-standard
1560 C compiler. They are now only supported with the @option{-E} switch.
1561 The preprocessor continues to support a pre-standard mode. See the GNU
1562 CPP manual for details.
1564 @item -fcond-mismatch
1565 @opindex fcond-mismatch
1566 Allow conditional expressions with mismatched types in the second and
1567 third arguments. The value of such an expression is void. This option
1568 is not supported for C++.
1570 @item -flax-vector-conversions
1571 @opindex flax-vector-conversions
1572 Allow implicit conversions between vectors with differing numbers of
1573 elements and/or incompatible element types. This option should not be
1576 @item -funsigned-char
1577 @opindex funsigned-char
1578 Let the type @code{char} be unsigned, like @code{unsigned char}.
1580 Each kind of machine has a default for what @code{char} should
1581 be. It is either like @code{unsigned char} by default or like
1582 @code{signed char} by default.
1584 Ideally, a portable program should always use @code{signed char} or
1585 @code{unsigned char} when it depends on the signedness of an object.
1586 But many programs have been written to use plain @code{char} and
1587 expect it to be signed, or expect it to be unsigned, depending on the
1588 machines they were written for. This option, and its inverse, let you
1589 make such a program work with the opposite default.
1591 The type @code{char} is always a distinct type from each of
1592 @code{signed char} or @code{unsigned char}, even though its behavior
1593 is always just like one of those two.
1596 @opindex fsigned-char
1597 Let the type @code{char} be signed, like @code{signed char}.
1599 Note that this is equivalent to @option{-fno-unsigned-char}, which is
1600 the negative form of @option{-funsigned-char}. Likewise, the option
1601 @option{-fno-signed-char} is equivalent to @option{-funsigned-char}.
1603 @item -fsigned-bitfields
1604 @itemx -funsigned-bitfields
1605 @itemx -fno-signed-bitfields
1606 @itemx -fno-unsigned-bitfields
1607 @opindex fsigned-bitfields
1608 @opindex funsigned-bitfields
1609 @opindex fno-signed-bitfields
1610 @opindex fno-unsigned-bitfields
1611 These options control whether a bit-field is signed or unsigned, when the
1612 declaration does not use either @code{signed} or @code{unsigned}. By
1613 default, such a bit-field is signed, because this is consistent: the
1614 basic integer types such as @code{int} are signed types.
1617 @node C++ Dialect Options
1618 @section Options Controlling C++ Dialect
1620 @cindex compiler options, C++
1621 @cindex C++ options, command line
1622 @cindex options, C++
1623 This section describes the command-line options that are only meaningful
1624 for C++ programs; but you can also use most of the GNU compiler options
1625 regardless of what language your program is in. For example, you
1626 might compile a file @code{firstClass.C} like this:
1629 g++ -g -frepo -O -c firstClass.C
1633 In this example, only @option{-frepo} is an option meant
1634 only for C++ programs; you can use the other options with any
1635 language supported by GCC@.
1637 Here is a list of options that are @emph{only} for compiling C++ programs:
1641 @item -fabi-version=@var{n}
1642 @opindex fabi-version
1643 Use version @var{n} of the C++ ABI@. Version 2 is the version of the
1644 C++ ABI that first appeared in G++ 3.4. Version 1 is the version of
1645 the C++ ABI that first appeared in G++ 3.2. Version 0 will always be
1646 the version that conforms most closely to the C++ ABI specification.
1647 Therefore, the ABI obtained using version 0 will change as ABI bugs
1650 The default is version 2.
1652 @item -fno-access-control
1653 @opindex fno-access-control
1654 Turn off all access checking. This switch is mainly useful for working
1655 around bugs in the access control code.
1659 Check that the pointer returned by @code{operator new} is non-null
1660 before attempting to modify the storage allocated. This check is
1661 normally unnecessary because the C++ standard specifies that
1662 @code{operator new} will only return @code{0} if it is declared
1663 @samp{throw()}, in which case the compiler will always check the
1664 return value even without this option. In all other cases, when
1665 @code{operator new} has a non-empty exception specification, memory
1666 exhaustion is signalled by throwing @code{std::bad_alloc}. See also
1667 @samp{new (nothrow)}.
1669 @item -fconserve-space
1670 @opindex fconserve-space
1671 Put uninitialized or runtime-initialized global variables into the
1672 common segment, as C does. This saves space in the executable at the
1673 cost of not diagnosing duplicate definitions. If you compile with this
1674 flag and your program mysteriously crashes after @code{main()} has
1675 completed, you may have an object that is being destroyed twice because
1676 two definitions were merged.
1678 This option is no longer useful on most targets, now that support has
1679 been added for putting variables into BSS without making them common.
1681 @item -ffriend-injection
1682 @opindex ffriend-injection
1683 Inject friend functions into the enclosing namespace, so that they are
1684 visible outside the scope of the class in which they are declared.
1685 Friend functions were documented to work this way in the old Annotated
1686 C++ Reference Manual, and versions of G++ before 4.1 always worked
1687 that way. However, in ISO C++ a friend function which is not declared
1688 in an enclosing scope can only be found using argument dependent
1689 lookup. This option causes friends to be injected as they were in
1692 This option is for compatibility, and may be removed in a future
1695 @item -fno-elide-constructors
1696 @opindex fno-elide-constructors
1697 The C++ standard allows an implementation to omit creating a temporary
1698 which is only used to initialize another object of the same type.
1699 Specifying this option disables that optimization, and forces G++ to
1700 call the copy constructor in all cases.
1702 @item -fno-enforce-eh-specs
1703 @opindex fno-enforce-eh-specs
1704 Don't generate code to check for violation of exception specifications
1705 at runtime. This option violates the C++ standard, but may be useful
1706 for reducing code size in production builds, much like defining
1707 @samp{NDEBUG}. This does not give user code permission to throw
1708 exceptions in violation of the exception specifications; the compiler
1709 will still optimize based on the specifications, so throwing an
1710 unexpected exception will result in undefined behavior.
1713 @itemx -fno-for-scope
1715 @opindex fno-for-scope
1716 If @option{-ffor-scope} is specified, the scope of variables declared in
1717 a @i{for-init-statement} is limited to the @samp{for} loop itself,
1718 as specified by the C++ standard.
1719 If @option{-fno-for-scope} is specified, the scope of variables declared in
1720 a @i{for-init-statement} extends to the end of the enclosing scope,
1721 as was the case in old versions of G++, and other (traditional)
1722 implementations of C++.
1724 The default if neither flag is given to follow the standard,
1725 but to allow and give a warning for old-style code that would
1726 otherwise be invalid, or have different behavior.
1728 @item -fno-gnu-keywords
1729 @opindex fno-gnu-keywords
1730 Do not recognize @code{typeof} as a keyword, so that code can use this
1731 word as an identifier. You can use the keyword @code{__typeof__} instead.
1732 @option{-ansi} implies @option{-fno-gnu-keywords}.
1734 @item -fno-implicit-templates
1735 @opindex fno-implicit-templates
1736 Never emit code for non-inline templates which are instantiated
1737 implicitly (i.e.@: by use); only emit code for explicit instantiations.
1738 @xref{Template Instantiation}, for more information.
1740 @item -fno-implicit-inline-templates
1741 @opindex fno-implicit-inline-templates
1742 Don't emit code for implicit instantiations of inline templates, either.
1743 The default is to handle inlines differently so that compiles with and
1744 without optimization will need the same set of explicit instantiations.
1746 @item -fno-implement-inlines
1747 @opindex fno-implement-inlines
1748 To save space, do not emit out-of-line copies of inline functions
1749 controlled by @samp{#pragma implementation}. This will cause linker
1750 errors if these functions are not inlined everywhere they are called.
1752 @item -fms-extensions
1753 @opindex fms-extensions
1754 Disable pedantic warnings about constructs used in MFC, such as implicit
1755 int and getting a pointer to member function via non-standard syntax.
1757 @item -fno-nonansi-builtins
1758 @opindex fno-nonansi-builtins
1759 Disable built-in declarations of functions that are not mandated by
1760 ANSI/ISO C@. These include @code{ffs}, @code{alloca}, @code{_exit},
1761 @code{index}, @code{bzero}, @code{conjf}, and other related functions.
1763 @item -fno-operator-names
1764 @opindex fno-operator-names
1765 Do not treat the operator name keywords @code{and}, @code{bitand},
1766 @code{bitor}, @code{compl}, @code{not}, @code{or} and @code{xor} as
1767 synonyms as keywords.
1769 @item -fno-optional-diags
1770 @opindex fno-optional-diags
1771 Disable diagnostics that the standard says a compiler does not need to
1772 issue. Currently, the only such diagnostic issued by G++ is the one for
1773 a name having multiple meanings within a class.
1776 @opindex fpermissive
1777 Downgrade some diagnostics about nonconformant code from errors to
1778 warnings. Thus, using @option{-fpermissive} will allow some
1779 nonconforming code to compile.
1783 Enable automatic template instantiation at link time. This option also
1784 implies @option{-fno-implicit-templates}. @xref{Template
1785 Instantiation}, for more information.
1789 Disable generation of information about every class with virtual
1790 functions for use by the C++ runtime type identification features
1791 (@samp{dynamic_cast} and @samp{typeid}). If you don't use those parts
1792 of the language, you can save some space by using this flag. Note that
1793 exception handling uses the same information, but it will generate it as
1794 needed. The @samp{dynamic_cast} operator can still be used for casts that
1795 do not require runtime type information, i.e.@: casts to @code{void *} or to
1796 unambiguous base classes.
1800 Emit statistics about front-end processing at the end of the compilation.
1801 This information is generally only useful to the G++ development team.
1803 @item -ftemplate-depth-@var{n}
1804 @opindex ftemplate-depth
1805 Set the maximum instantiation depth for template classes to @var{n}.
1806 A limit on the template instantiation depth is needed to detect
1807 endless recursions during template class instantiation. ANSI/ISO C++
1808 conforming programs must not rely on a maximum depth greater than 17.
1810 @item -fno-threadsafe-statics
1811 @opindex fno-threadsafe-statics
1812 Do not emit the extra code to use the routines specified in the C++
1813 ABI for thread-safe initialization of local statics. You can use this
1814 option to reduce code size slightly in code that doesn't need to be
1817 @item -fuse-cxa-atexit
1818 @opindex fuse-cxa-atexit
1819 Register destructors for objects with static storage duration with the
1820 @code{__cxa_atexit} function rather than the @code{atexit} function.
1821 This option is required for fully standards-compliant handling of static
1822 destructors, but will only work if your C library supports
1823 @code{__cxa_atexit}.
1825 @item -fno-use-cxa-get-exception-ptr
1826 @opindex fno-use-cxa-get-exception-ptr
1827 Don't use the @code{__cxa_get_exception_ptr} runtime routine. This
1828 will cause @code{std::uncaught_exception} to be incorrect, but is necessary
1829 if the runtime routine is not available.
1831 @item -fvisibility-inlines-hidden
1832 @opindex fvisibility-inlines-hidden
1833 This switch declares that the user does not attempt to compare
1834 pointers to inline methods where the addresses of the two functions
1835 were taken in different shared objects.
1837 The effect of this is that GCC may, effectively, mark inline methods with
1838 @code{__attribute__ ((visibility ("hidden")))} so that they do not
1839 appear in the export table of a DSO and do not require a PLT indirection
1840 when used within the DSO@. Enabling this option can have a dramatic effect
1841 on load and link times of a DSO as it massively reduces the size of the
1842 dynamic export table when the library makes heavy use of templates.
1844 The behavior of this switch is not quite the same as marking the
1845 methods as hidden directly, because it does not affect static variables
1846 local to the function or cause the compiler to deduce that
1847 the function is defined in only one shared object.
1849 You may mark a method as having a visibility explicitly to negate the
1850 effect of the switch for that method. For example, if you do want to
1851 compare pointers to a particular inline method, you might mark it as
1852 having default visibility. Marking the enclosing class with explicit
1853 visibility will have no effect.
1855 Explicitly instantiated inline methods are unaffected by this option
1856 as their linkage might otherwise cross a shared library boundary.
1857 @xref{Template Instantiation}.
1859 @item -fvisibility-ms-compat
1860 @opindex fvisibility-ms-compat
1861 This flag attempts to use visibility settings to make GCC's C++
1862 linkage model compatible with that of Microsoft Visual Studio.
1864 The flag makes these changes to GCC's linkage model:
1868 It sets the default visibility to @code{hidden}, like
1869 @option{-fvisibility=hidden}.
1872 Types, but not their members, are not hidden by default.
1875 The One Definition Rule is relaxed for types without explicit
1876 visibility specifications which are defined in more than one different
1877 shared object: those declarations are permitted if they would have
1878 been permitted when this option was not used.
1881 In new code it is better to use @option{-fvisibility=hidden} and
1882 export those classes which are intended to be externally visible.
1883 Unfortunately it is possible for code to rely, perhaps accidentally,
1884 on the Visual Studio behavior.
1886 Among the consequences of these changes are that static data members
1887 of the same type with the same name but defined in different shared
1888 objects will be different, so changing one will not change the other;
1889 and that pointers to function members defined in different shared
1890 objects may not compare equal. When this flag is given, it is a
1891 violation of the ODR to define types with the same name differently.
1895 Do not use weak symbol support, even if it is provided by the linker.
1896 By default, G++ will use weak symbols if they are available. This
1897 option exists only for testing, and should not be used by end-users;
1898 it will result in inferior code and has no benefits. This option may
1899 be removed in a future release of G++.
1903 Do not search for header files in the standard directories specific to
1904 C++, but do still search the other standard directories. (This option
1905 is used when building the C++ library.)
1908 In addition, these optimization, warning, and code generation options
1909 have meanings only for C++ programs:
1912 @item -fno-default-inline
1913 @opindex fno-default-inline
1914 Do not assume @samp{inline} for functions defined inside a class scope.
1915 @xref{Optimize Options,,Options That Control Optimization}. Note that these
1916 functions will have linkage like inline functions; they just won't be
1919 @item -Wabi @r{(C++ and Objective-C++ only)}
1922 Warn when G++ generates code that is probably not compatible with the
1923 vendor-neutral C++ ABI@. Although an effort has been made to warn about
1924 all such cases, there are probably some cases that are not warned about,
1925 even though G++ is generating incompatible code. There may also be
1926 cases where warnings are emitted even though the code that is generated
1929 You should rewrite your code to avoid these warnings if you are
1930 concerned about the fact that code generated by G++ may not be binary
1931 compatible with code generated by other compilers.
1933 The known incompatibilities at this point include:
1938 Incorrect handling of tail-padding for bit-fields. G++ may attempt to
1939 pack data into the same byte as a base class. For example:
1942 struct A @{ virtual void f(); int f1 : 1; @};
1943 struct B : public A @{ int f2 : 1; @};
1947 In this case, G++ will place @code{B::f2} into the same byte
1948 as@code{A::f1}; other compilers will not. You can avoid this problem
1949 by explicitly padding @code{A} so that its size is a multiple of the
1950 byte size on your platform; that will cause G++ and other compilers to
1951 layout @code{B} identically.
1954 Incorrect handling of tail-padding for virtual bases. G++ does not use
1955 tail padding when laying out virtual bases. For example:
1958 struct A @{ virtual void f(); char c1; @};
1959 struct B @{ B(); char c2; @};
1960 struct C : public A, public virtual B @{@};
1964 In this case, G++ will not place @code{B} into the tail-padding for
1965 @code{A}; other compilers will. You can avoid this problem by
1966 explicitly padding @code{A} so that its size is a multiple of its
1967 alignment (ignoring virtual base classes); that will cause G++ and other
1968 compilers to layout @code{C} identically.
1971 Incorrect handling of bit-fields with declared widths greater than that
1972 of their underlying types, when the bit-fields appear in a union. For
1976 union U @{ int i : 4096; @};
1980 Assuming that an @code{int} does not have 4096 bits, G++ will make the
1981 union too small by the number of bits in an @code{int}.
1984 Empty classes can be placed at incorrect offsets. For example:
1994 struct C : public B, public A @{@};
1998 G++ will place the @code{A} base class of @code{C} at a nonzero offset;
1999 it should be placed at offset zero. G++ mistakenly believes that the
2000 @code{A} data member of @code{B} is already at offset zero.
2003 Names of template functions whose types involve @code{typename} or
2004 template template parameters can be mangled incorrectly.
2007 template <typename Q>
2008 void f(typename Q::X) @{@}
2010 template <template <typename> class Q>
2011 void f(typename Q<int>::X) @{@}
2015 Instantiations of these templates may be mangled incorrectly.
2019 @item -Wctor-dtor-privacy @r{(C++ and Objective-C++ only)}
2020 @opindex Wctor-dtor-privacy
2021 @opindex Wno-ctor-dtor-privacy
2022 Warn when a class seems unusable because all the constructors or
2023 destructors in that class are private, and it has neither friends nor
2024 public static member functions.
2026 @item -Wnon-virtual-dtor @r{(C++ and Objective-C++ only)}
2027 @opindex Wnon-virtual-dtor
2028 @opindex Wno-non-virtual-dtor
2029 Warn when a class has virtual functions and accessible non-virtual
2030 destructor, in which case it would be possible but unsafe to delete
2031 an instance of a derived class through a pointer to the base class.
2032 This warning is also enabled if -Weffc++ is specified.
2034 @item -Wreorder @r{(C++ and Objective-C++ only)}
2036 @opindex Wno-reorder
2037 @cindex reordering, warning
2038 @cindex warning for reordering of member initializers
2039 Warn when the order of member initializers given in the code does not
2040 match the order in which they must be executed. For instance:
2046 A(): j (0), i (1) @{ @}
2050 The compiler will rearrange the member initializers for @samp{i}
2051 and @samp{j} to match the declaration order of the members, emitting
2052 a warning to that effect. This warning is enabled by @option{-Wall}.
2055 The following @option{-W@dots{}} options are not affected by @option{-Wall}.
2058 @item -Weffc++ @r{(C++ and Objective-C++ only)}
2061 Warn about violations of the following style guidelines from Scott Meyers'
2062 @cite{Effective C++} book:
2066 Item 11: Define a copy constructor and an assignment operator for classes
2067 with dynamically allocated memory.
2070 Item 12: Prefer initialization to assignment in constructors.
2073 Item 14: Make destructors virtual in base classes.
2076 Item 15: Have @code{operator=} return a reference to @code{*this}.
2079 Item 23: Don't try to return a reference when you must return an object.
2083 Also warn about violations of the following style guidelines from
2084 Scott Meyers' @cite{More Effective C++} book:
2088 Item 6: Distinguish between prefix and postfix forms of increment and
2089 decrement operators.
2092 Item 7: Never overload @code{&&}, @code{||}, or @code{,}.
2096 When selecting this option, be aware that the standard library
2097 headers do not obey all of these guidelines; use @samp{grep -v}
2098 to filter out those warnings.
2100 @item -Wno-deprecated @r{(C++ and Objective-C++ only)}
2101 @opindex Wno-deprecated
2102 @opindex Wdeprecated
2103 Do not warn about usage of deprecated features. @xref{Deprecated Features}.
2105 @item -Wstrict-null-sentinel @r{(C++ and Objective-C++ only)}
2106 @opindex Wstrict-null-sentinel
2107 @opindex Wno-strict-null-sentinel
2108 Warn also about the use of an uncasted @code{NULL} as sentinel. When
2109 compiling only with GCC this is a valid sentinel, as @code{NULL} is defined
2110 to @code{__null}. Although it is a null pointer constant not a null pointer,
2111 it is guaranteed to of the same size as a pointer. But this use is
2112 not portable across different compilers.
2114 @item -Wno-non-template-friend @r{(C++ and Objective-C++ only)}
2115 @opindex Wno-non-template-friend
2116 @opindex Wnon-template-friend
2117 Disable warnings when non-templatized friend functions are declared
2118 within a template. Since the advent of explicit template specification
2119 support in G++, if the name of the friend is an unqualified-id (i.e.,
2120 @samp{friend foo(int)}), the C++ language specification demands that the
2121 friend declare or define an ordinary, nontemplate function. (Section
2122 14.5.3). Before G++ implemented explicit specification, unqualified-ids
2123 could be interpreted as a particular specialization of a templatized
2124 function. Because this non-conforming behavior is no longer the default
2125 behavior for G++, @option{-Wnon-template-friend} allows the compiler to
2126 check existing code for potential trouble spots and is on by default.
2127 This new compiler behavior can be turned off with
2128 @option{-Wno-non-template-friend} which keeps the conformant compiler code
2129 but disables the helpful warning.
2131 @item -Wold-style-cast @r{(C++ and Objective-C++ only)}
2132 @opindex Wold-style-cast
2133 @opindex Wno-old-style-cast
2134 Warn if an old-style (C-style) cast to a non-void type is used within
2135 a C++ program. The new-style casts (@samp{dynamic_cast},
2136 @samp{static_cast}, @samp{reinterpret_cast}, and @samp{const_cast}) are
2137 less vulnerable to unintended effects and much easier to search for.
2139 @item -Woverloaded-virtual @r{(C++ and Objective-C++ only)}
2140 @opindex Woverloaded-virtual
2141 @opindex Wno-overloaded-virtual
2142 @cindex overloaded virtual fn, warning
2143 @cindex warning for overloaded virtual fn
2144 Warn when a function declaration hides virtual functions from a
2145 base class. For example, in:
2152 struct B: public A @{
2157 the @code{A} class version of @code{f} is hidden in @code{B}, and code
2165 will fail to compile.
2167 @item -Wno-pmf-conversions @r{(C++ and Objective-C++ only)}
2168 @opindex Wno-pmf-conversions
2169 @opindex Wpmf-conversions
2170 Disable the diagnostic for converting a bound pointer to member function
2173 @item -Wsign-promo @r{(C++ and Objective-C++ only)}
2174 @opindex Wsign-promo
2175 @opindex Wno-sign-promo
2176 Warn when overload resolution chooses a promotion from unsigned or
2177 enumerated type to a signed type, over a conversion to an unsigned type of
2178 the same size. Previous versions of G++ would try to preserve
2179 unsignedness, but the standard mandates the current behavior.
2184 A& operator = (int);
2194 In this example, G++ will synthesize a default @samp{A& operator =
2195 (const A&);}, while cfront will use the user-defined @samp{operator =}.
2198 @node Objective-C and Objective-C++ Dialect Options
2199 @section Options Controlling Objective-C and Objective-C++ Dialects
2201 @cindex compiler options, Objective-C and Objective-C++
2202 @cindex Objective-C and Objective-C++ options, command line
2203 @cindex options, Objective-C and Objective-C++
2204 (NOTE: This manual does not describe the Objective-C and Objective-C++
2205 languages themselves. See @xref{Standards,,Language Standards
2206 Supported by GCC}, for references.)
2208 This section describes the command-line options that are only meaningful
2209 for Objective-C and Objective-C++ programs, but you can also use most of
2210 the language-independent GNU compiler options.
2211 For example, you might compile a file @code{some_class.m} like this:
2214 gcc -g -fgnu-runtime -O -c some_class.m
2218 In this example, @option{-fgnu-runtime} is an option meant only for
2219 Objective-C and Objective-C++ programs; you can use the other options with
2220 any language supported by GCC@.
2222 Note that since Objective-C is an extension of the C language, Objective-C
2223 compilations may also use options specific to the C front-end (e.g.,
2224 @option{-Wtraditional}). Similarly, Objective-C++ compilations may use
2225 C++-specific options (e.g., @option{-Wabi}).
2227 Here is a list of options that are @emph{only} for compiling Objective-C
2228 and Objective-C++ programs:
2231 @item -fconstant-string-class=@var{class-name}
2232 @opindex fconstant-string-class
2233 Use @var{class-name} as the name of the class to instantiate for each
2234 literal string specified with the syntax @code{@@"@dots{}"}. The default
2235 class name is @code{NXConstantString} if the GNU runtime is being used, and
2236 @code{NSConstantString} if the NeXT runtime is being used (see below). The
2237 @option{-fconstant-cfstrings} option, if also present, will override the
2238 @option{-fconstant-string-class} setting and cause @code{@@"@dots{}"} literals
2239 to be laid out as constant CoreFoundation strings.
2242 @opindex fgnu-runtime
2243 Generate object code compatible with the standard GNU Objective-C
2244 runtime. This is the default for most types of systems.
2246 @item -fnext-runtime
2247 @opindex fnext-runtime
2248 Generate output compatible with the NeXT runtime. This is the default
2249 for NeXT-based systems, including Darwin and Mac OS X@. The macro
2250 @code{__NEXT_RUNTIME__} is predefined if (and only if) this option is
2253 @item -fno-nil-receivers
2254 @opindex fno-nil-receivers
2255 Assume that all Objective-C message dispatches (e.g.,
2256 @code{[receiver message:arg]}) in this translation unit ensure that the receiver
2257 is not @code{nil}. This allows for more efficient entry points in the runtime
2258 to be used. Currently, this option is only available in conjunction with
2259 the NeXT runtime on Mac OS X 10.3 and later.
2261 @item -fobjc-call-cxx-cdtors
2262 @opindex fobjc-call-cxx-cdtors
2263 For each Objective-C class, check if any of its instance variables is a
2264 C++ object with a non-trivial default constructor. If so, synthesize a
2265 special @code{- (id) .cxx_construct} instance method that will run
2266 non-trivial default constructors on any such instance variables, in order,
2267 and then return @code{self}. Similarly, check if any instance variable
2268 is a C++ object with a non-trivial destructor, and if so, synthesize a
2269 special @code{- (void) .cxx_destruct} method that will run
2270 all such default destructors, in reverse order.
2272 The @code{- (id) .cxx_construct} and/or @code{- (void) .cxx_destruct} methods
2273 thusly generated will only operate on instance variables declared in the
2274 current Objective-C class, and not those inherited from superclasses. It
2275 is the responsibility of the Objective-C runtime to invoke all such methods
2276 in an object's inheritance hierarchy. The @code{- (id) .cxx_construct} methods
2277 will be invoked by the runtime immediately after a new object
2278 instance is allocated; the @code{- (void) .cxx_destruct} methods will
2279 be invoked immediately before the runtime deallocates an object instance.
2281 As of this writing, only the NeXT runtime on Mac OS X 10.4 and later has
2282 support for invoking the @code{- (id) .cxx_construct} and
2283 @code{- (void) .cxx_destruct} methods.
2285 @item -fobjc-direct-dispatch
2286 @opindex fobjc-direct-dispatch
2287 Allow fast jumps to the message dispatcher. On Darwin this is
2288 accomplished via the comm page.
2290 @item -fobjc-exceptions
2291 @opindex fobjc-exceptions
2292 Enable syntactic support for structured exception handling in Objective-C,
2293 similar to what is offered by C++ and Java. This option is
2294 unavailable in conjunction with the NeXT runtime on Mac OS X 10.2 and
2303 @@catch (AnObjCClass *exc) @{
2310 @@catch (AnotherClass *exc) @{
2313 @@catch (id allOthers) @{
2323 The @code{@@throw} statement may appear anywhere in an Objective-C or
2324 Objective-C++ program; when used inside of a @code{@@catch} block, the
2325 @code{@@throw} may appear without an argument (as shown above), in which case
2326 the object caught by the @code{@@catch} will be rethrown.
2328 Note that only (pointers to) Objective-C objects may be thrown and
2329 caught using this scheme. When an object is thrown, it will be caught
2330 by the nearest @code{@@catch} clause capable of handling objects of that type,
2331 analogously to how @code{catch} blocks work in C++ and Java. A
2332 @code{@@catch(id @dots{})} clause (as shown above) may also be provided to catch
2333 any and all Objective-C exceptions not caught by previous @code{@@catch}
2336 The @code{@@finally} clause, if present, will be executed upon exit from the
2337 immediately preceding @code{@@try @dots{} @@catch} section. This will happen
2338 regardless of whether any exceptions are thrown, caught or rethrown
2339 inside the @code{@@try @dots{} @@catch} section, analogously to the behavior
2340 of the @code{finally} clause in Java.
2342 There are several caveats to using the new exception mechanism:
2346 Although currently designed to be binary compatible with @code{NS_HANDLER}-style
2347 idioms provided by the @code{NSException} class, the new
2348 exceptions can only be used on Mac OS X 10.3 (Panther) and later
2349 systems, due to additional functionality needed in the (NeXT) Objective-C
2353 As mentioned above, the new exceptions do not support handling
2354 types other than Objective-C objects. Furthermore, when used from
2355 Objective-C++, the Objective-C exception model does not interoperate with C++
2356 exceptions at this time. This means you cannot @code{@@throw} an exception
2357 from Objective-C and @code{catch} it in C++, or vice versa
2358 (i.e., @code{throw @dots{} @@catch}).
2361 The @option{-fobjc-exceptions} switch also enables the use of synchronization
2362 blocks for thread-safe execution:
2365 @@synchronized (ObjCClass *guard) @{
2370 Upon entering the @code{@@synchronized} block, a thread of execution shall
2371 first check whether a lock has been placed on the corresponding @code{guard}
2372 object by another thread. If it has, the current thread shall wait until
2373 the other thread relinquishes its lock. Once @code{guard} becomes available,
2374 the current thread will place its own lock on it, execute the code contained in
2375 the @code{@@synchronized} block, and finally relinquish the lock (thereby
2376 making @code{guard} available to other threads).
2378 Unlike Java, Objective-C does not allow for entire methods to be marked
2379 @code{@@synchronized}. Note that throwing exceptions out of
2380 @code{@@synchronized} blocks is allowed, and will cause the guarding object
2381 to be unlocked properly.
2385 Enable garbage collection (GC) in Objective-C and Objective-C++ programs.
2387 @item -freplace-objc-classes
2388 @opindex freplace-objc-classes
2389 Emit a special marker instructing @command{ld(1)} not to statically link in
2390 the resulting object file, and allow @command{dyld(1)} to load it in at
2391 run time instead. This is used in conjunction with the Fix-and-Continue
2392 debugging mode, where the object file in question may be recompiled and
2393 dynamically reloaded in the course of program execution, without the need
2394 to restart the program itself. Currently, Fix-and-Continue functionality
2395 is only available in conjunction with the NeXT runtime on Mac OS X 10.3
2400 When compiling for the NeXT runtime, the compiler ordinarily replaces calls
2401 to @code{objc_getClass("@dots{}")} (when the name of the class is known at
2402 compile time) with static class references that get initialized at load time,
2403 which improves run-time performance. Specifying the @option{-fzero-link} flag
2404 suppresses this behavior and causes calls to @code{objc_getClass("@dots{}")}
2405 to be retained. This is useful in Zero-Link debugging mode, since it allows
2406 for individual class implementations to be modified during program execution.
2410 Dump interface declarations for all classes seen in the source file to a
2411 file named @file{@var{sourcename}.decl}.
2413 @item -Wassign-intercept @r{(Objective-C and Objective-C++ only)}
2414 @opindex Wassign-intercept
2415 @opindex Wno-assign-intercept
2416 Warn whenever an Objective-C assignment is being intercepted by the
2419 @item -Wno-protocol @r{(Objective-C and Objective-C++ only)}
2420 @opindex Wno-protocol
2422 If a class is declared to implement a protocol, a warning is issued for
2423 every method in the protocol that is not implemented by the class. The
2424 default behavior is to issue a warning for every method not explicitly
2425 implemented in the class, even if a method implementation is inherited
2426 from the superclass. If you use the @option{-Wno-protocol} option, then
2427 methods inherited from the superclass are considered to be implemented,
2428 and no warning is issued for them.
2430 @item -Wselector @r{(Objective-C and Objective-C++ only)}
2432 @opindex Wno-selector
2433 Warn if multiple methods of different types for the same selector are
2434 found during compilation. The check is performed on the list of methods
2435 in the final stage of compilation. Additionally, a check is performed
2436 for each selector appearing in a @code{@@selector(@dots{})}
2437 expression, and a corresponding method for that selector has been found
2438 during compilation. Because these checks scan the method table only at
2439 the end of compilation, these warnings are not produced if the final
2440 stage of compilation is not reached, for example because an error is
2441 found during compilation, or because the @option{-fsyntax-only} option is
2444 @item -Wstrict-selector-match @r{(Objective-C and Objective-C++ only)}
2445 @opindex Wstrict-selector-match
2446 @opindex Wno-strict-selector-match
2447 Warn if multiple methods with differing argument and/or return types are
2448 found for a given selector when attempting to send a message using this
2449 selector to a receiver of type @code{id} or @code{Class}. When this flag
2450 is off (which is the default behavior), the compiler will omit such warnings
2451 if any differences found are confined to types which share the same size
2454 @item -Wundeclared-selector @r{(Objective-C and Objective-C++ only)}
2455 @opindex Wundeclared-selector
2456 @opindex Wno-undeclared-selector
2457 Warn if a @code{@@selector(@dots{})} expression referring to an
2458 undeclared selector is found. A selector is considered undeclared if no
2459 method with that name has been declared before the
2460 @code{@@selector(@dots{})} expression, either explicitly in an
2461 @code{@@interface} or @code{@@protocol} declaration, or implicitly in
2462 an @code{@@implementation} section. This option always performs its
2463 checks as soon as a @code{@@selector(@dots{})} expression is found,
2464 while @option{-Wselector} only performs its checks in the final stage of
2465 compilation. This also enforces the coding style convention
2466 that methods and selectors must be declared before being used.
2468 @item -print-objc-runtime-info
2469 @opindex print-objc-runtime-info
2470 Generate C header describing the largest structure that is passed by
2475 @node Language Independent Options
2476 @section Options to Control Diagnostic Messages Formatting
2477 @cindex options to control diagnostics formatting
2478 @cindex diagnostic messages
2479 @cindex message formatting
2481 Traditionally, diagnostic messages have been formatted irrespective of
2482 the output device's aspect (e.g.@: its width, @dots{}). The options described
2483 below can be used to control the diagnostic messages formatting
2484 algorithm, e.g.@: how many characters per line, how often source location
2485 information should be reported. Right now, only the C++ front end can
2486 honor these options. However it is expected, in the near future, that
2487 the remaining front ends would be able to digest them correctly.
2490 @item -fmessage-length=@var{n}
2491 @opindex fmessage-length
2492 Try to format error messages so that they fit on lines of about @var{n}
2493 characters. The default is 72 characters for @command{g++} and 0 for the rest of
2494 the front ends supported by GCC@. If @var{n} is zero, then no
2495 line-wrapping will be done; each error message will appear on a single
2498 @opindex fdiagnostics-show-location
2499 @item -fdiagnostics-show-location=once
2500 Only meaningful in line-wrapping mode. Instructs the diagnostic messages
2501 reporter to emit @emph{once} source location information; that is, in
2502 case the message is too long to fit on a single physical line and has to
2503 be wrapped, the source location won't be emitted (as prefix) again,
2504 over and over, in subsequent continuation lines. This is the default
2507 @item -fdiagnostics-show-location=every-line
2508 Only meaningful in line-wrapping mode. Instructs the diagnostic
2509 messages reporter to emit the same source location information (as
2510 prefix) for physical lines that result from the process of breaking
2511 a message which is too long to fit on a single line.
2513 @item -fdiagnostics-show-option
2514 @opindex fdiagnostics-show-option
2515 This option instructs the diagnostic machinery to add text to each
2516 diagnostic emitted, which indicates which command line option directly
2517 controls that diagnostic, when such an option is known to the
2518 diagnostic machinery.
2520 @item -Wcoverage-mismatch
2521 @opindex Wcoverage-mismatch
2522 Warn if feedback profiles do not match when using the
2523 @option{-fprofile-use} option.
2524 If a source file was changed between @option{-fprofile-gen} and
2525 @option{-fprofile-use}, the files with the profile feedback can fail
2526 to match the source file and GCC can not use the profile feedback
2527 information. By default, GCC emits an error message in this case.
2528 The option @option{-Wcoverage-mismatch} emits a warning instead of an
2529 error. GCC does not use appropriate feedback profiles, so using this
2530 option can result in poorly optimized code. This option is useful
2531 only in the case of very minor changes such as bug fixes to an
2536 @node Warning Options
2537 @section Options to Request or Suppress Warnings
2538 @cindex options to control warnings
2539 @cindex warning messages
2540 @cindex messages, warning
2541 @cindex suppressing warnings
2543 Warnings are diagnostic messages that report constructions which
2544 are not inherently erroneous but which are risky or suggest there
2545 may have been an error.
2547 The following language-independent options do not enable specific
2548 warnings but control the kinds of diagnostics produced by GCC.
2551 @cindex syntax checking
2553 @opindex fsyntax-only
2554 Check the code for syntax errors, but don't do anything beyond that.
2558 Inhibit all warning messages.
2563 Make all warnings into errors.
2568 Make the specified warning into an error. The specifier for a warning
2569 is appended, for example @option{-Werror=switch} turns the warnings
2570 controlled by @option{-Wswitch} into errors. This switch takes a
2571 negative form, to be used to negate @option{-Werror} for specific
2572 warnings, for example @option{-Wno-error=switch} makes
2573 @option{-Wswitch} warnings not be errors, even when @option{-Werror}
2574 is in effect. You can use the @option{-fdiagnostics-show-option}
2575 option to have each controllable warning amended with the option which
2576 controls it, to determine what to use with this option.
2578 Note that specifying @option{-Werror=}@var{foo} automatically implies
2579 @option{-W}@var{foo}. However, @option{-Wno-error=}@var{foo} does not
2582 @item -Wfatal-errors
2583 @opindex Wfatal-errors
2584 @opindex Wno-fatal-errors
2585 This option causes the compiler to abort compilation on the first error
2586 occurred rather than trying to keep going and printing further error
2591 You can request many specific warnings with options beginning
2592 @samp{-W}, for example @option{-Wimplicit} to request warnings on
2593 implicit declarations. Each of these specific warning options also
2594 has a negative form beginning @samp{-Wno-} to turn off warnings; for
2595 example, @option{-Wno-implicit}. This manual lists only one of the
2596 two forms, whichever is not the default. For further,
2597 language-specific options also refer to @ref{C++ Dialect Options} and
2598 @ref{Objective-C and Objective-C++ Dialect Options}.
2603 Issue all the warnings demanded by strict ISO C and ISO C++;
2604 reject all programs that use forbidden extensions, and some other
2605 programs that do not follow ISO C and ISO C++. For ISO C, follows the
2606 version of the ISO C standard specified by any @option{-std} option used.
2608 Valid ISO C and ISO C++ programs should compile properly with or without
2609 this option (though a rare few will require @option{-ansi} or a
2610 @option{-std} option specifying the required version of ISO C)@. However,
2611 without this option, certain GNU extensions and traditional C and C++
2612 features are supported as well. With this option, they are rejected.
2614 @option{-pedantic} does not cause warning messages for use of the
2615 alternate keywords whose names begin and end with @samp{__}. Pedantic
2616 warnings are also disabled in the expression that follows
2617 @code{__extension__}. However, only system header files should use
2618 these escape routes; application programs should avoid them.
2619 @xref{Alternate Keywords}.
2621 Some users try to use @option{-pedantic} to check programs for strict ISO
2622 C conformance. They soon find that it does not do quite what they want:
2623 it finds some non-ISO practices, but not all---only those for which
2624 ISO C @emph{requires} a diagnostic, and some others for which
2625 diagnostics have been added.
2627 A feature to report any failure to conform to ISO C might be useful in
2628 some instances, but would require considerable additional work and would
2629 be quite different from @option{-pedantic}. We don't have plans to
2630 support such a feature in the near future.
2632 Where the standard specified with @option{-std} represents a GNU
2633 extended dialect of C, such as @samp{gnu89} or @samp{gnu99}, there is a
2634 corresponding @dfn{base standard}, the version of ISO C on which the GNU
2635 extended dialect is based. Warnings from @option{-pedantic} are given
2636 where they are required by the base standard. (It would not make sense
2637 for such warnings to be given only for features not in the specified GNU
2638 C dialect, since by definition the GNU dialects of C include all
2639 features the compiler supports with the given option, and there would be
2640 nothing to warn about.)
2642 @item -pedantic-errors
2643 @opindex pedantic-errors
2644 Like @option{-pedantic}, except that errors are produced rather than
2650 This enables all the warnings about constructions that some users
2651 consider questionable, and that are easy to avoid (or modify to
2652 prevent the warning), even in conjunction with macros. This also
2653 enables some language-specific warnings described in @ref{C++ Dialect
2654 Options} and @ref{Objective-C and Objective-C++ Dialect Options}.
2656 @option{-Wall} turns on the following warning flags:
2658 @gccoptlist{-Waddress @gol
2659 -Warray-bounds @r{(only with} @option{-O2}@r{)} @gol
2661 -Wchar-subscripts @gol
2663 -Wimplicit-function-declaration @gol
2666 -Wmain @r{(only for C/ObjC and unless} @option{-ffreestanding}@r{)} @gol
2667 -Wmissing-braces @gol
2673 -Wsequence-point @gol
2674 -Wsign-compare @r{(only in C++)} @gol
2675 -Wstrict-aliasing @gol
2676 -Wstrict-overflow=1 @gol
2679 -Wuninitialized @r{(only with} @option{-O1} @r{and above)} @gol
2680 -Wunknown-pragmas @gol
2681 -Wunused-function @gol
2684 -Wunused-variable @gol
2687 Note that some warning flags are not implied by @option{-Wall}. Some of
2688 them warn about constructions that users generally do not consider
2689 questionable, but which occasionally you might wish to check for;
2690 others warn about constructions that are necessary or hard to avoid in
2691 some cases, and there is no simple way to modify the code to suppress
2692 the warning. Some of them are enabled by @option{-Wextra} but many of
2693 them must be enabled individually.
2699 This enables some extra warning flags that are not enabled by
2700 @option{-Wall}. (This option used to be called @option{-W}. The older
2701 name is still supported, but the newer name is more descriptive.)
2703 @gccoptlist{-Wclobbered @gol
2705 -Wignored-qualifiers @gol
2706 -Wmissing-field-initializers @gol
2707 -Wmissing-parameter-type @r{(C only)} @gol
2708 -Wold-style-declaration @r{(C only)} @gol
2709 -Woverride-init @gol
2712 -Wuninitialized @r{(only with} @option{-O1} @r{and above)} @gol
2713 -Wunused-parameter @r{(only with} @option{-Wunused} @r{or} @option{-Wall}@r{)} @gol
2716 The option @option{-Wextra} also prints warning messages for the
2722 A pointer is compared against integer zero with @samp{<}, @samp{<=},
2723 @samp{>}, or @samp{>=}.
2726 (C++ only) An enumerator and a non-enumerator both appear in a
2727 conditional expression.
2730 (C++ only) A non-static reference or non-static @samp{const} member
2731 appears in a class without constructors.
2734 (C++ only) Ambiguous virtual bases.
2737 (C++ only) Subscripting an array which has been declared @samp{register}.
2740 (C++ only) Taking the address of a variable which has been declared
2744 (C++ only) A base class is not initialized in a derived class' copy
2752 Inhibit warning messages about the use of @samp{#import}.
2754 @item -Wchar-subscripts
2755 @opindex Wchar-subscripts
2756 @opindex Wno-char-subscripts
2757 Warn if an array subscript has type @code{char}. This is a common cause
2758 of error, as programmers often forget that this type is signed on some
2760 This warning is enabled by @option{-Wall}.
2764 @opindex Wno-comment
2765 Warn whenever a comment-start sequence @samp{/*} appears in a @samp{/*}
2766 comment, or whenever a Backslash-Newline appears in a @samp{//} comment.
2767 This warning is enabled by @option{-Wall}.
2772 @opindex ffreestanding
2773 @opindex fno-builtin
2774 Check calls to @code{printf} and @code{scanf}, etc., to make sure that
2775 the arguments supplied have types appropriate to the format string
2776 specified, and that the conversions specified in the format string make
2777 sense. This includes standard functions, and others specified by format
2778 attributes (@pxref{Function Attributes}), in the @code{printf},
2779 @code{scanf}, @code{strftime} and @code{strfmon} (an X/Open extension,
2780 not in the C standard) families (or other target-specific families).
2781 Which functions are checked without format attributes having been
2782 specified depends on the standard version selected, and such checks of
2783 functions without the attribute specified are disabled by
2784 @option{-ffreestanding} or @option{-fno-builtin}.
2786 The formats are checked against the format features supported by GNU
2787 libc version 2.2. These include all ISO C90 and C99 features, as well
2788 as features from the Single Unix Specification and some BSD and GNU
2789 extensions. Other library implementations may not support all these
2790 features; GCC does not support warning about features that go beyond a
2791 particular library's limitations. However, if @option{-pedantic} is used
2792 with @option{-Wformat}, warnings will be given about format features not
2793 in the selected standard version (but not for @code{strfmon} formats,
2794 since those are not in any version of the C standard). @xref{C Dialect
2795 Options,,Options Controlling C Dialect}.
2797 Since @option{-Wformat} also checks for null format arguments for
2798 several functions, @option{-Wformat} also implies @option{-Wnonnull}.
2800 @option{-Wformat} is included in @option{-Wall}. For more control over some
2801 aspects of format checking, the options @option{-Wformat-y2k},
2802 @option{-Wno-format-extra-args}, @option{-Wno-format-zero-length},
2803 @option{-Wformat-nonliteral}, @option{-Wformat-security}, and
2804 @option{-Wformat=2} are available, but are not included in @option{-Wall}.
2807 @opindex Wformat-y2k
2808 @opindex Wno-format-y2k
2809 If @option{-Wformat} is specified, also warn about @code{strftime}
2810 formats which may yield only a two-digit year.
2812 @item -Wno-format-extra-args
2813 @opindex Wno-format-extra-args
2814 @opindex Wformat-extra-args
2815 If @option{-Wformat} is specified, do not warn about excess arguments to a
2816 @code{printf} or @code{scanf} format function. The C standard specifies
2817 that such arguments are ignored.
2819 Where the unused arguments lie between used arguments that are
2820 specified with @samp{$} operand number specifications, normally
2821 warnings are still given, since the implementation could not know what
2822 type to pass to @code{va_arg} to skip the unused arguments. However,
2823 in the case of @code{scanf} formats, this option will suppress the
2824 warning if the unused arguments are all pointers, since the Single
2825 Unix Specification says that such unused arguments are allowed.
2827 @item -Wno-format-zero-length @r{(C and Objective-C only)}
2828 @opindex Wno-format-zero-length
2829 @opindex Wformat-zero-length
2830 If @option{-Wformat} is specified, do not warn about zero-length formats.
2831 The C standard specifies that zero-length formats are allowed.
2833 @item -Wformat-nonliteral
2834 @opindex Wformat-nonliteral
2835 @opindex Wno-format-nonliteral
2836 If @option{-Wformat} is specified, also warn if the format string is not a
2837 string literal and so cannot be checked, unless the format function
2838 takes its format arguments as a @code{va_list}.
2840 @item -Wformat-security
2841 @opindex Wformat-security
2842 @opindex Wno-format-security
2843 If @option{-Wformat} is specified, also warn about uses of format
2844 functions that represent possible security problems. At present, this
2845 warns about calls to @code{printf} and @code{scanf} functions where the
2846 format string is not a string literal and there are no format arguments,
2847 as in @code{printf (foo);}. This may be a security hole if the format
2848 string came from untrusted input and contains @samp{%n}. (This is
2849 currently a subset of what @option{-Wformat-nonliteral} warns about, but
2850 in future warnings may be added to @option{-Wformat-security} that are not
2851 included in @option{-Wformat-nonliteral}.)
2855 @opindex Wno-format=2
2856 Enable @option{-Wformat} plus format checks not included in
2857 @option{-Wformat}. Currently equivalent to @samp{-Wformat
2858 -Wformat-nonliteral -Wformat-security -Wformat-y2k}.
2860 @item -Wnonnull @r{(C and Objective-C only)}
2862 @opindex Wno-nonnull
2863 Warn about passing a null pointer for arguments marked as
2864 requiring a non-null value by the @code{nonnull} function attribute.
2866 @option{-Wnonnull} is included in @option{-Wall} and @option{-Wformat}. It
2867 can be disabled with the @option{-Wno-nonnull} option.
2869 @item -Winit-self @r{(C, C++, Objective-C and Objective-C++ only)}
2871 @opindex Wno-init-self
2872 Warn about uninitialized variables which are initialized with themselves.
2873 Note this option can only be used with the @option{-Wuninitialized} option,
2874 which in turn only works with @option{-O1} and above.
2876 For example, GCC will warn about @code{i} being uninitialized in the
2877 following snippet only when @option{-Winit-self} has been specified:
2888 @item -Wimplicit-int @r{(C and Objective-C only)}
2889 @opindex Wimplicit-int
2890 @opindex Wno-implicit-int
2891 Warn when a declaration does not specify a type.
2892 This warning is enabled by @option{-Wall}.
2894 @item -Wimplicit-function-declaration @r{(C and Objective-C only)}
2895 @opindex Wimplicit-function-declaration
2896 @opindex Wno-implicit-function-declaration
2897 Give a warning whenever a function is used before being declared. In
2898 C99 mode (@option{-std=c99} or @option{-std=gnu99}), this warning is
2899 enabled by default and it is made into an error by
2900 @option{-pedantic-errors}. This warning is also enabled by
2905 @opindex Wno-implicit
2906 Same as @option{-Wimplicit-int} and @option{-Wimplicit-function-declaration}.
2907 This warning is enabled by @option{-Wall}.
2909 @item -Wignored-qualifiers @r{(C and C++ only)}
2910 @opindex Wignored-qualifiers
2911 @opindex Wno-ignored-qualifiers
2912 Warn if the return type of a function has a type qualifier
2913 such as @code{const}. For ISO C such a type qualifier has no effect,
2914 since the value returned by a function is not an lvalue.
2915 For C++, the warning is only emitted for scalar types or @code{void}.
2916 ISO C prohibits qualified @code{void} return types on function
2917 definitions, so such return types always receive a warning
2918 even without this option.
2920 This warning is also enabled by @option{-Wextra}.
2925 Warn if the type of @samp{main} is suspicious. @samp{main} should be a
2926 function with external linkage, returning int, taking either zero
2927 arguments, two, or three arguments of appropriate types.
2928 This warning is enabled by @option{-Wall}.
2930 @item -Wmissing-braces
2931 @opindex Wmissing-braces
2932 @opindex Wno-missing-braces
2933 Warn if an aggregate or union initializer is not fully bracketed. In
2934 the following example, the initializer for @samp{a} is not fully
2935 bracketed, but that for @samp{b} is fully bracketed.
2938 int a[2][2] = @{ 0, 1, 2, 3 @};
2939 int b[2][2] = @{ @{ 0, 1 @}, @{ 2, 3 @} @};
2942 This warning is enabled by @option{-Wall}.
2944 @item -Wmissing-include-dirs @r{(C, C++, Objective-C and Objective-C++ only)}
2945 @opindex Wmissing-include-dirs
2946 @opindex Wno-missing-include-dirs
2947 Warn if a user-supplied include directory does not exist.
2950 @opindex Wparentheses
2951 @opindex Wno-parentheses
2952 Warn if parentheses are omitted in certain contexts, such
2953 as when there is an assignment in a context where a truth value
2954 is expected, or when operators are nested whose precedence people
2955 often get confused about.
2957 Also warn if a comparison like @samp{x<=y<=z} appears; this is
2958 equivalent to @samp{(x<=y ? 1 : 0) <= z}, which is a different
2959 interpretation from that of ordinary mathematical notation.
2961 Also warn about constructions where there may be confusion to which
2962 @code{if} statement an @code{else} branch belongs. Here is an example of
2977 In C/C++, every @code{else} branch belongs to the innermost possible
2978 @code{if} statement, which in this example is @code{if (b)}. This is
2979 often not what the programmer expected, as illustrated in the above
2980 example by indentation the programmer chose. When there is the
2981 potential for this confusion, GCC will issue a warning when this flag
2982 is specified. To eliminate the warning, add explicit braces around
2983 the innermost @code{if} statement so there is no way the @code{else}
2984 could belong to the enclosing @code{if}. The resulting code would
3001 This warning is enabled by @option{-Wall}.
3003 @item -Wsequence-point
3004 @opindex Wsequence-point
3005 @opindex Wno-sequence-point
3006 Warn about code that may have undefined semantics because of violations
3007 of sequence point rules in the C and C++ standards.
3009 The C and C++ standards defines the order in which expressions in a C/C++
3010 program are evaluated in terms of @dfn{sequence points}, which represent
3011 a partial ordering between the execution of parts of the program: those
3012 executed before the sequence point, and those executed after it. These
3013 occur after the evaluation of a full expression (one which is not part
3014 of a larger expression), after the evaluation of the first operand of a
3015 @code{&&}, @code{||}, @code{? :} or @code{,} (comma) operator, before a
3016 function is called (but after the evaluation of its arguments and the
3017 expression denoting the called function), and in certain other places.
3018 Other than as expressed by the sequence point rules, the order of
3019 evaluation of subexpressions of an expression is not specified. All
3020 these rules describe only a partial order rather than a total order,
3021 since, for example, if two functions are called within one expression
3022 with no sequence point between them, the order in which the functions
3023 are called is not specified. However, the standards committee have
3024 ruled that function calls do not overlap.
3026 It is not specified when between sequence points modifications to the
3027 values of objects take effect. Programs whose behavior depends on this
3028 have undefined behavior; the C and C++ standards specify that ``Between
3029 the previous and next sequence point an object shall have its stored
3030 value modified at most once by the evaluation of an expression.
3031 Furthermore, the prior value shall be read only to determine the value
3032 to be stored.''. If a program breaks these rules, the results on any
3033 particular implementation are entirely unpredictable.
3035 Examples of code with undefined behavior are @code{a = a++;}, @code{a[n]
3036 = b[n++]} and @code{a[i++] = i;}. Some more complicated cases are not
3037 diagnosed by this option, and it may give an occasional false positive
3038 result, but in general it has been found fairly effective at detecting
3039 this sort of problem in programs.
3041 The standard is worded confusingly, therefore there is some debate
3042 over the precise meaning of the sequence point rules in subtle cases.
3043 Links to discussions of the problem, including proposed formal
3044 definitions, may be found on the GCC readings page, at
3045 @w{@uref{http://gcc.gnu.org/readings.html}}.
3047 This warning is enabled by @option{-Wall} for C and C++.
3050 @opindex Wreturn-type
3051 @opindex Wno-return-type
3052 Warn whenever a function is defined with a return-type that defaults
3053 to @code{int}. Also warn about any @code{return} statement with no
3054 return-value in a function whose return-type is not @code{void}
3055 (falling off the end of the function body is considered returning
3056 without a value), and about a @code{return} statement with a
3057 expression in a function whose return-type is @code{void}.
3059 For C++, a function without return type always produces a diagnostic
3060 message, even when @option{-Wno-return-type} is specified. The only
3061 exceptions are @samp{main} and functions defined in system headers.
3063 This warning is enabled by @option{-Wall}.
3068 Warn whenever a @code{switch} statement has an index of enumerated type
3069 and lacks a @code{case} for one or more of the named codes of that
3070 enumeration. (The presence of a @code{default} label prevents this
3071 warning.) @code{case} labels outside the enumeration range also
3072 provoke warnings when this option is used.
3073 This warning is enabled by @option{-Wall}.
3075 @item -Wswitch-default
3076 @opindex Wswitch-default
3077 @opindex Wno-switch-default
3078 Warn whenever a @code{switch} statement does not have a @code{default}
3082 @opindex Wswitch-enum
3083 @opindex Wno-switch-enum
3084 Warn whenever a @code{switch} statement has an index of enumerated type
3085 and lacks a @code{case} for one or more of the named codes of that
3086 enumeration. @code{case} labels outside the enumeration range also
3087 provoke warnings when this option is used.
3091 @opindex Wno-trigraphs
3092 Warn if any trigraphs are encountered that might change the meaning of
3093 the program (trigraphs within comments are not warned about).
3094 This warning is enabled by @option{-Wall}.
3096 @item -Wunused-function
3097 @opindex Wunused-function
3098 @opindex Wno-unused-function
3099 Warn whenever a static function is declared but not defined or a
3100 non-inline static function is unused.
3101 This warning is enabled by @option{-Wall}.
3103 @item -Wunused-label
3104 @opindex Wunused-label
3105 @opindex Wno-unused-label
3106 Warn whenever a label is declared but not used.
3107 This warning is enabled by @option{-Wall}.
3109 To suppress this warning use the @samp{unused} attribute
3110 (@pxref{Variable Attributes}).
3112 @item -Wunused-parameter
3113 @opindex Wunused-parameter
3114 @opindex Wno-unused-parameter
3115 Warn whenever a function parameter is unused aside from its declaration.
3117 To suppress this warning use the @samp{unused} attribute
3118 (@pxref{Variable Attributes}).
3120 @item -Wunused-variable
3121 @opindex Wunused-variable
3122 @opindex Wno-unused-variable
3123 Warn whenever a local variable or non-constant static variable is unused
3124 aside from its declaration.
3125 This warning is enabled by @option{-Wall}.
3127 To suppress this warning use the @samp{unused} attribute
3128 (@pxref{Variable Attributes}).
3130 @item -Wunused-value
3131 @opindex Wunused-value
3132 @opindex Wno-unused-value
3133 Warn whenever a statement computes a result that is explicitly not
3134 used. To suppress this warning cast the unused expression to
3135 @samp{void}. This includes an expression-statement or the left-hand
3136 side of a comma expression that contains no side effects. For example,
3137 an expression such as @samp{x[i,j]} will cause a warning, while
3138 @samp{x[(void)i,j]} will not.
3140 This warning is enabled by @option{-Wall}.
3145 All the above @option{-Wunused} options combined.
3147 In order to get a warning about an unused function parameter, you must
3148 either specify @samp{-Wextra -Wunused} (note that @samp{-Wall} implies
3149 @samp{-Wunused}), or separately specify @option{-Wunused-parameter}.
3151 @item -Wuninitialized
3152 @opindex Wuninitialized
3153 @opindex Wno-uninitialized
3154 Warn if an automatic variable is used without first being initialized or
3155 if a variable may be clobbered by a @code{setjmp} call.
3157 These warnings are possible only in optimizing compilation,
3158 because they require data flow information that is computed only
3159 when optimizing. If you do not specify @option{-O}, you will not get
3160 these warnings. Instead, GCC will issue a warning about @option{-Wuninitialized}
3161 requiring @option{-O}.
3163 If you want to warn about code which uses the uninitialized value of the
3164 variable in its own initializer, use the @option{-Winit-self} option.
3166 These warnings occur for individual uninitialized or clobbered
3167 elements of structure, union or array variables as well as for
3168 variables which are uninitialized or clobbered as a whole. They do
3169 not occur for variables or elements declared @code{volatile}. Because
3170 these warnings depend on optimization, the exact variables or elements
3171 for which there are warnings will depend on the precise optimization
3172 options and version of GCC used.
3174 Note that there may be no warning about a variable that is used only
3175 to compute a value that itself is never used, because such
3176 computations may be deleted by data flow analysis before the warnings
3179 These warnings are made optional because GCC is not smart
3180 enough to see all the reasons why the code might be correct
3181 despite appearing to have an error. Here is one example of how
3202 If the value of @code{y} is always 1, 2 or 3, then @code{x} is
3203 always initialized, but GCC doesn't know this. Here is
3204 another common case:
3209 if (change_y) save_y = y, y = new_y;
3211 if (change_y) y = save_y;
3216 This has no bug because @code{save_y} is used only if it is set.
3218 @cindex @code{longjmp} warnings
3219 This option also warns when a non-volatile automatic variable might be
3220 changed by a call to @code{longjmp}. These warnings as well are possible
3221 only in optimizing compilation.
3223 The compiler sees only the calls to @code{setjmp}. It cannot know
3224 where @code{longjmp} will be called; in fact, a signal handler could
3225 call it at any point in the code. As a result, you may get a warning
3226 even when there is in fact no problem because @code{longjmp} cannot
3227 in fact be called at the place which would cause a problem.
3229 Some spurious warnings can be avoided if you declare all the functions
3230 you use that never return as @code{noreturn}. @xref{Function
3233 This warning is enabled by @option{-Wall} or @option{-Wextra} in
3234 optimizing compilations (@option{-O1} and above).
3236 @item -Wunknown-pragmas
3237 @opindex Wunknown-pragmas
3238 @opindex Wno-unknown-pragmas
3239 @cindex warning for unknown pragmas
3240 @cindex unknown pragmas, warning
3241 @cindex pragmas, warning of unknown
3242 Warn when a #pragma directive is encountered which is not understood by
3243 GCC@. If this command line option is used, warnings will even be issued
3244 for unknown pragmas in system header files. This is not the case if
3245 the warnings were only enabled by the @option{-Wall} command line option.
3248 @opindex Wno-pragmas
3250 Do not warn about misuses of pragmas, such as incorrect parameters,
3251 invalid syntax, or conflicts between pragmas. See also
3252 @samp{-Wunknown-pragmas}.
3254 @item -Wstrict-aliasing
3255 @opindex Wstrict-aliasing
3256 @opindex Wno-strict-aliasing
3257 This option is only active when @option{-fstrict-aliasing} is active.
3258 It warns about code which might break the strict aliasing rules that the
3259 compiler is using for optimization. The warning does not catch all
3260 cases, but does attempt to catch the more common pitfalls. It is
3261 included in @option{-Wall}.
3262 It is equivalent to @option{-Wstrict-aliasing=3}
3264 @item -Wstrict-aliasing=n
3265 @opindex Wstrict-aliasing=n
3266 @opindex Wno-strict-aliasing=n
3267 This option is only active when @option{-fstrict-aliasing} is active.
3268 It warns about code which might break the strict aliasing rules that the
3269 compiler is using for optimization.
3270 Higher levels correspond to higher accuracy (fewer false positives).
3271 Higher levels also correspond to more effort, similar to the way -O works.
3272 @option{-Wstrict-aliasing} is equivalent to @option{-Wstrict-aliasing=n},
3275 Level 1: Most aggressive, quick, least accurate.
3276 Possibly useful when higher levels
3277 do not warn but -fstrict-aliasing still breaks the code, as it has very few
3278 false negatives. However, it has many false positives.
3279 Warns for all pointer conversions between possibly incompatible types,
3280 even if never dereferenced. Runs in the frontend only.
3282 Level 2: Aggressive, quick, not too precise.
3283 May still have many false positives (not as many as level 1 though),
3284 and few false negatives (but possibly more than level 1).
3285 Unlike level 1, it only warns when an address is taken. Warns about
3286 incomplete types. Runs in the frontend only.
3288 Level 3 (default for @option{-Wstrict-aliasing}):
3289 Should have very few false positives and few false
3290 negatives. Slightly slower than levels 1 or 2 when optimization is enabled.
3291 Takes care of the common punn+dereference pattern in the frontend:
3292 @code{*(int*)&some_float}.
3293 If optimization is enabled, it also runs in the backend, where it deals
3294 with multiple statement cases using flow-sensitive points-to information.
3295 Only warns when the converted pointer is dereferenced.
3296 Does not warn about incomplete types.
3298 @item -Wstrict-overflow
3299 @itemx -Wstrict-overflow=@var{n}
3300 @opindex Wstrict-overflow
3301 @opindex Wno-strict-overflow
3302 This option is only active when @option{-fstrict-overflow} is active.
3303 It warns about cases where the compiler optimizes based on the
3304 assumption that signed overflow does not occur. Note that it does not
3305 warn about all cases where the code might overflow: it only warns
3306 about cases where the compiler implements some optimization. Thus
3307 this warning depends on the optimization level.
3309 An optimization which assumes that signed overflow does not occur is
3310 perfectly safe if the values of the variables involved are such that
3311 overflow never does, in fact, occur. Therefore this warning can
3312 easily give a false positive: a warning about code which is not
3313 actually a problem. To help focus on important issues, several
3314 warning levels are defined. No warnings are issued for the use of
3315 undefined signed overflow when estimating how many iterations a loop
3316 will require, in particular when determining whether a loop will be
3320 @item -Wstrict-overflow=1
3321 Warn about cases which are both questionable and easy to avoid. For
3322 example: @code{x + 1 > x}; with @option{-fstrict-overflow}, the
3323 compiler will simplify this to @code{1}. This level of
3324 @option{-Wstrict-overflow} is enabled by @option{-Wall}; higher levels
3325 are not, and must be explicitly requested.
3327 @item -Wstrict-overflow=2
3328 Also warn about other cases where a comparison is simplified to a
3329 constant. For example: @code{abs (x) >= 0}. This can only be
3330 simplified when @option{-fstrict-overflow} is in effect, because
3331 @code{abs (INT_MIN)} overflows to @code{INT_MIN}, which is less than
3332 zero. @option{-Wstrict-overflow} (with no level) is the same as
3333 @option{-Wstrict-overflow=2}.
3335 @item -Wstrict-overflow=3
3336 Also warn about other cases where a comparison is simplified. For
3337 example: @code{x + 1 > 1} will be simplified to @code{x > 0}.
3339 @item -Wstrict-overflow=4
3340 Also warn about other simplifications not covered by the above cases.
3341 For example: @code{(x * 10) / 5} will be simplified to @code{x * 2}.
3343 @item -Wstrict-overflow=5
3344 Also warn about cases where the compiler reduces the magnitude of a
3345 constant involved in a comparison. For example: @code{x + 2 > y} will
3346 be simplified to @code{x + 1 >= y}. This is reported only at the
3347 highest warning level because this simplification applies to many
3348 comparisons, so this warning level will give a very large number of
3352 @item -Warray-bounds
3353 @opindex Wno-array-bounds
3354 @opindex Warray-bounds
3355 This option is only active when @option{-ftree-vrp} is active
3356 (default for -O2 and above). It warns about subscripts to arrays
3357 that are always out of bounds. This warning is enabled by @option{-Wall}.
3359 @item -Wno-div-by-zero
3360 @opindex Wno-div-by-zero
3361 @opindex Wdiv-by-zero
3362 Do not warn about compile-time integer division by zero. Floating point
3363 division by zero is not warned about, as it can be a legitimate way of
3364 obtaining infinities and NaNs.
3366 @item -Wsystem-headers
3367 @opindex Wsystem-headers
3368 @opindex Wno-system-headers
3369 @cindex warnings from system headers
3370 @cindex system headers, warnings from
3371 Print warning messages for constructs found in system header files.
3372 Warnings from system headers are normally suppressed, on the assumption
3373 that they usually do not indicate real problems and would only make the
3374 compiler output harder to read. Using this command line option tells
3375 GCC to emit warnings from system headers as if they occurred in user
3376 code. However, note that using @option{-Wall} in conjunction with this
3377 option will @emph{not} warn about unknown pragmas in system
3378 headers---for that, @option{-Wunknown-pragmas} must also be used.
3381 @opindex Wfloat-equal
3382 @opindex Wno-float-equal
3383 Warn if floating point values are used in equality comparisons.
3385 The idea behind this is that sometimes it is convenient (for the
3386 programmer) to consider floating-point values as approximations to
3387 infinitely precise real numbers. If you are doing this, then you need
3388 to compute (by analyzing the code, or in some other way) the maximum or
3389 likely maximum error that the computation introduces, and allow for it
3390 when performing comparisons (and when producing output, but that's a
3391 different problem). In particular, instead of testing for equality, you
3392 would check to see whether the two values have ranges that overlap; and
3393 this is done with the relational operators, so equality comparisons are
3396 @item -Wtraditional @r{(C and Objective-C only)}
3397 @opindex Wtraditional
3398 @opindex Wno-traditional
3399 Warn about certain constructs that behave differently in traditional and
3400 ISO C@. Also warn about ISO C constructs that have no traditional C
3401 equivalent, and/or problematic constructs which should be avoided.
3405 Macro parameters that appear within string literals in the macro body.
3406 In traditional C macro replacement takes place within string literals,
3407 but does not in ISO C@.
3410 In traditional C, some preprocessor directives did not exist.
3411 Traditional preprocessors would only consider a line to be a directive
3412 if the @samp{#} appeared in column 1 on the line. Therefore
3413 @option{-Wtraditional} warns about directives that traditional C
3414 understands but would ignore because the @samp{#} does not appear as the
3415 first character on the line. It also suggests you hide directives like
3416 @samp{#pragma} not understood by traditional C by indenting them. Some
3417 traditional implementations would not recognize @samp{#elif}, so it
3418 suggests avoiding it altogether.
3421 A function-like macro that appears without arguments.
3424 The unary plus operator.
3427 The @samp{U} integer constant suffix, or the @samp{F} or @samp{L} floating point
3428 constant suffixes. (Traditional C does support the @samp{L} suffix on integer
3429 constants.) Note, these suffixes appear in macros defined in the system
3430 headers of most modern systems, e.g.@: the @samp{_MIN}/@samp{_MAX} macros in @code{<limits.h>}.
3431 Use of these macros in user code might normally lead to spurious
3432 warnings, however GCC's integrated preprocessor has enough context to
3433 avoid warning in these cases.
3436 A function declared external in one block and then used after the end of
3440 A @code{switch} statement has an operand of type @code{long}.
3443 A non-@code{static} function declaration follows a @code{static} one.
3444 This construct is not accepted by some traditional C compilers.
3447 The ISO type of an integer constant has a different width or
3448 signedness from its traditional type. This warning is only issued if
3449 the base of the constant is ten. I.e.@: hexadecimal or octal values, which
3450 typically represent bit patterns, are not warned about.
3453 Usage of ISO string concatenation is detected.
3456 Initialization of automatic aggregates.
3459 Identifier conflicts with labels. Traditional C lacks a separate
3460 namespace for labels.
3463 Initialization of unions. If the initializer is zero, the warning is
3464 omitted. This is done under the assumption that the zero initializer in
3465 user code appears conditioned on e.g.@: @code{__STDC__} to avoid missing
3466 initializer warnings and relies on default initialization to zero in the
3470 Conversions by prototypes between fixed/floating point values and vice
3471 versa. The absence of these prototypes when compiling with traditional
3472 C would cause serious problems. This is a subset of the possible
3473 conversion warnings, for the full set use @option{-Wtraditional-conversion}.
3476 Use of ISO C style function definitions. This warning intentionally is
3477 @emph{not} issued for prototype declarations or variadic functions
3478 because these ISO C features will appear in your code when using
3479 libiberty's traditional C compatibility macros, @code{PARAMS} and
3480 @code{VPARAMS}. This warning is also bypassed for nested functions
3481 because that feature is already a GCC extension and thus not relevant to
3482 traditional C compatibility.
3485 @item -Wtraditional-conversion @r{(C and Objective-C only)}
3486 @opindex Wtraditional-conversion
3487 @opindex Wno-traditional-conversion
3488 Warn if a prototype causes a type conversion that is different from what
3489 would happen to the same argument in the absence of a prototype. This
3490 includes conversions of fixed point to floating and vice versa, and
3491 conversions changing the width or signedness of a fixed point argument
3492 except when the same as the default promotion.
3494 @item -Wdeclaration-after-statement @r{(C and Objective-C only)}
3495 @opindex Wdeclaration-after-statement
3496 @opindex Wno-declaration-after-statement
3497 Warn when a declaration is found after a statement in a block. This
3498 construct, known from C++, was introduced with ISO C99 and is by default
3499 allowed in GCC@. It is not supported by ISO C90 and was not supported by
3500 GCC versions before GCC 3.0. @xref{Mixed Declarations}.
3505 Warn if an undefined identifier is evaluated in an @samp{#if} directive.
3507 @item -Wno-endif-labels
3508 @opindex Wno-endif-labels
3509 @opindex Wendif-labels
3510 Do not warn whenever an @samp{#else} or an @samp{#endif} are followed by text.
3515 Warn whenever a local variable shadows another local variable, parameter or
3516 global variable or whenever a built-in function is shadowed.
3518 @item -Wlarger-than-@var{len}
3519 @opindex Wlarger-than-@var{len}
3520 Warn whenever an object of larger than @var{len} bytes is defined.
3522 @item -Wframe-larger-than=@var{len}
3523 @opindex Wframe-larger-than
3524 Warn whenever the size of a function frame is larger than @var{len} bytes.
3526 @item -Wunsafe-loop-optimizations
3527 @opindex Wunsafe-loop-optimizations
3528 @opindex Wno-unsafe-loop-optimizations
3529 Warn if the loop cannot be optimized because the compiler could not
3530 assume anything on the bounds of the loop indices. With
3531 @option{-funsafe-loop-optimizations} warn if the compiler made
3534 @item -Wpointer-arith
3535 @opindex Wpointer-arith
3536 @opindex Wno-pointer-arith
3537 Warn about anything that depends on the ``size of'' a function type or
3538 of @code{void}. GNU C assigns these types a size of 1, for
3539 convenience in calculations with @code{void *} pointers and pointers
3540 to functions. In C++, warn also when an arithmetic operation involves
3541 @code{NULL}. This warning is also enabled by @option{-pedantic}.
3544 @opindex Wtype-limits
3545 @opindex Wno-type-limits
3546 Warn if a comparison is always true or always false due to the limited
3547 range of the data type, but do not warn for constant expressions. For
3548 example, warn if an unsigned variable is compared against zero with
3549 @samp{<} or @samp{>=}. This warning is also enabled by
3552 @item -Wbad-function-cast @r{(C and Objective-C only)}
3553 @opindex Wbad-function-cast
3554 @opindex Wno-bad-function-cast
3555 Warn whenever a function call is cast to a non-matching type.
3556 For example, warn if @code{int malloc()} is cast to @code{anything *}.
3558 @item -Wc++-compat @r{(C and Objective-C only)}
3559 Warn about ISO C constructs that are outside of the common subset of
3560 ISO C and ISO C++, e.g.@: request for implicit conversion from
3561 @code{void *} to a pointer to non-@code{void} type.
3563 @item -Wc++0x-compat @r{(C++ and Objective-C++ only)}
3564 Warn about C++ constructs whose meaning differs between ISO C++ 1998 and
3565 ISO C++ 200x, e.g., identifiers in ISO C++ 1998 that will become keywords
3566 in ISO C++ 200x. This warning is enabled by @option{-Wall}.
3570 @opindex Wno-cast-qual
3571 Warn whenever a pointer is cast so as to remove a type qualifier from
3572 the target type. For example, warn if a @code{const char *} is cast
3573 to an ordinary @code{char *}.
3576 @opindex Wcast-align
3577 @opindex Wno-cast-align
3578 Warn whenever a pointer is cast such that the required alignment of the
3579 target is increased. For example, warn if a @code{char *} is cast to
3580 an @code{int *} on machines where integers can only be accessed at
3581 two- or four-byte boundaries.
3583 @item -Wwrite-strings
3584 @opindex Wwrite-strings
3585 @opindex Wno-write-strings
3586 When compiling C, give string constants the type @code{const
3587 char[@var{length}]} so that
3588 copying the address of one into a non-@code{const} @code{char *}
3589 pointer will get a warning; when compiling C++, warn about the
3590 deprecated conversion from string literals to @code{char *}. This
3591 warning, by default, is enabled for C++ programs.
3592 These warnings will help you find at
3593 compile time code that can try to write into a string constant, but
3594 only if you have been very careful about using @code{const} in
3595 declarations and prototypes. Otherwise, it will just be a nuisance;
3596 this is why we did not make @option{-Wall} request these warnings.
3600 @opindex Wno-clobbered
3601 Warn for variables that might be changed by @samp{longjmp} or
3602 @samp{vfork}. This warning is also enabled by @option{-Wextra}.
3605 @opindex Wconversion
3606 @opindex Wno-conversion
3607 Warn for implicit conversions that may alter a value. This includes
3608 conversions between real and integer, like @code{abs (x)} when
3609 @code{x} is @code{double}; conversions between signed and unsigned,
3610 like @code{unsigned ui = -1}; and conversions to smaller types, like
3611 @code{sqrtf (M_PI)}. Do not warn for explicit casts like @code{abs
3612 ((int) x)} and @code{ui = (unsigned) -1}, or if the value is not
3613 changed by the conversion like in @code{abs (2.0)}. Warnings about
3614 conversions between signed and unsigned integers can be disabled by
3615 using @option{-Wno-sign-conversion}.
3617 For C++, also warn for conversions between @code{NULL} and non-pointer
3618 types; confusing overload resolution for user-defined conversions; and
3619 conversions that will never use a type conversion operator:
3620 conversions to @code{void}, the same type, a base class or a reference
3621 to them. Warnings about conversions between signed and unsigned
3622 integers are disabled by default in C++ unless
3623 @option{-Wsign-conversion} is explicitly enabled.
3626 @opindex Wempty-body
3627 @opindex Wno-empty-body
3628 Warn if an empty body occurs in an @samp{if}, @samp{else} or @samp{do
3629 while} statement. Additionally, in C++, warn when an empty body occurs
3630 in a @samp{while} or @samp{for} statement with no whitespacing before
3631 the semicolon. This warning is also enabled by @option{-Wextra}.
3633 @item -Wsign-compare
3634 @opindex Wsign-compare
3635 @opindex Wno-sign-compare
3636 @cindex warning for comparison of signed and unsigned values
3637 @cindex comparison of signed and unsigned values, warning
3638 @cindex signed and unsigned values, comparison warning
3639 Warn when a comparison between signed and unsigned values could produce
3640 an incorrect result when the signed value is converted to unsigned.
3641 This warning is also enabled by @option{-Wextra}; to get the other warnings
3642 of @option{-Wextra} without this warning, use @samp{-Wextra -Wno-sign-compare}.
3644 @item -Wsign-conversion
3645 @opindex Wsign-conversion
3646 @opindex Wno-sign-conversion
3647 Warn for implicit conversions that may change the sign of an integer
3648 value, like assigning a signed integer expression to an unsigned
3649 integer variable. An explicit cast silences the warning. In C, this
3650 option is enabled also by @option{-Wconversion}.
3654 @opindex Wno-address
3655 Warn about suspicious uses of memory addresses. These include using
3656 the address of a function in a conditional expression, such as
3657 @code{void func(void); if (func)}, and comparisons against the memory
3658 address of a string literal, such as @code{if (x == "abc")}. Such
3659 uses typically indicate a programmer error: the address of a function
3660 always evaluates to true, so their use in a conditional usually
3661 indicate that the programmer forgot the parentheses in a function
3662 call; and comparisons against string literals result in unspecified
3663 behavior and are not portable in C, so they usually indicate that the
3664 programmer intended to use @code{strcmp}. This warning is enabled by
3668 @opindex Wlogical-op
3669 @opindex Wno-logical-op
3670 Warn about suspicious uses of logical operators in expressions.
3671 This includes using logical operators in contexts where a
3672 bit-wise operator is likely to be expected.
3674 @item -Waggregate-return
3675 @opindex Waggregate-return
3676 @opindex Wno-aggregate-return
3677 Warn if any functions that return structures or unions are defined or
3678 called. (In languages where you can return an array, this also elicits
3681 @item -Wno-attributes
3682 @opindex Wno-attributes
3683 @opindex Wattributes
3684 Do not warn if an unexpected @code{__attribute__} is used, such as
3685 unrecognized attributes, function attributes applied to variables,
3686 etc. This will not stop errors for incorrect use of supported
3689 @item -Wstrict-prototypes @r{(C and Objective-C only)}
3690 @opindex Wstrict-prototypes
3691 @opindex Wno-strict-prototypes
3692 Warn if a function is declared or defined without specifying the
3693 argument types. (An old-style function definition is permitted without
3694 a warning if preceded by a declaration which specifies the argument
3697 @item -Wold-style-declaration @r{(C and Objective-C only)}
3698 @opindex Wold-style-declaration
3699 @opindex Wno-old-style-declaration
3700 Warn for obsolescent usages, according to the C Standard, in a
3701 declaration. For example, warn if storage-class specifiers like
3702 @code{static} are not the first things in a declaration. This warning
3703 is also enabled by @option{-Wextra}.
3705 @item -Wold-style-definition @r{(C and Objective-C only)}
3706 @opindex Wold-style-definition
3707 @opindex Wno-old-style-definition
3708 Warn if an old-style function definition is used. A warning is given
3709 even if there is a previous prototype.
3711 @item -Wmissing-parameter-type @r{(C and Objective-C only)}
3712 @opindex Wmissing-parameter-type
3713 @opindex Wno-missing-parameter-type
3714 A function parameter is declared without a type specifier in K&R-style
3721 This warning is also enabled by @option{-Wextra}.
3723 @item -Wmissing-prototypes @r{(C and Objective-C only)}
3724 @opindex Wmissing-prototypes
3725 @opindex Wno-missing-prototypes
3726 Warn if a global function is defined without a previous prototype
3727 declaration. This warning is issued even if the definition itself
3728 provides a prototype. The aim is to detect global functions that fail
3729 to be declared in header files.
3731 @item -Wmissing-declarations
3732 @opindex Wmissing-declarations
3733 @opindex Wno-missing-declarations
3734 Warn if a global function is defined without a previous declaration.
3735 Do so even if the definition itself provides a prototype.
3736 Use this option to detect global functions that are not declared in
3737 header files. In C++, no warnings are issued for function templates,
3738 or for inline functions, or for functions in anonymous namespaces.
3740 @item -Wmissing-field-initializers
3741 @opindex Wmissing-field-initializers
3742 @opindex Wno-missing-field-initializers
3746 Warn if a structure's initializer has some fields missing. For
3747 example, the following code would cause such a warning, because
3748 @code{x.h} is implicitly zero:
3751 struct s @{ int f, g, h; @};
3752 struct s x = @{ 3, 4 @};
3755 This option does not warn about designated initializers, so the following
3756 modification would not trigger a warning:
3759 struct s @{ int f, g, h; @};
3760 struct s x = @{ .f = 3, .g = 4 @};
3763 This warning is included in @option{-Wextra}. To get other @option{-Wextra}
3764 warnings without this one, use @samp{-Wextra -Wno-missing-field-initializers}.
3766 @item -Wmissing-noreturn
3767 @opindex Wmissing-noreturn
3768 @opindex Wno-missing-noreturn
3769 Warn about functions which might be candidates for attribute @code{noreturn}.
3770 Note these are only possible candidates, not absolute ones. Care should
3771 be taken to manually verify functions actually do not ever return before
3772 adding the @code{noreturn} attribute, otherwise subtle code generation
3773 bugs could be introduced. You will not get a warning for @code{main} in
3774 hosted C environments.
3776 @item -Wmissing-format-attribute
3777 @opindex Wmissing-format-attribute
3778 @opindex Wno-missing-format-attribute
3781 Warn about function pointers which might be candidates for @code{format}
3782 attributes. Note these are only possible candidates, not absolute ones.
3783 GCC will guess that function pointers with @code{format} attributes that
3784 are used in assignment, initialization, parameter passing or return
3785 statements should have a corresponding @code{format} attribute in the
3786 resulting type. I.e.@: the left-hand side of the assignment or
3787 initialization, the type of the parameter variable, or the return type
3788 of the containing function respectively should also have a @code{format}
3789 attribute to avoid the warning.
3791 GCC will also warn about function definitions which might be
3792 candidates for @code{format} attributes. Again, these are only
3793 possible candidates. GCC will guess that @code{format} attributes
3794 might be appropriate for any function that calls a function like
3795 @code{vprintf} or @code{vscanf}, but this might not always be the
3796 case, and some functions for which @code{format} attributes are
3797 appropriate may not be detected.
3799 @item -Wno-multichar
3800 @opindex Wno-multichar
3802 Do not warn if a multicharacter constant (@samp{'FOOF'}) is used.
3803 Usually they indicate a typo in the user's code, as they have
3804 implementation-defined values, and should not be used in portable code.
3806 @item -Wnormalized=<none|id|nfc|nfkc>
3807 @opindex Wnormalized=
3810 @cindex character set, input normalization
3811 In ISO C and ISO C++, two identifiers are different if they are
3812 different sequences of characters. However, sometimes when characters
3813 outside the basic ASCII character set are used, you can have two
3814 different character sequences that look the same. To avoid confusion,
3815 the ISO 10646 standard sets out some @dfn{normalization rules} which
3816 when applied ensure that two sequences that look the same are turned into
3817 the same sequence. GCC can warn you if you are using identifiers which
3818 have not been normalized; this option controls that warning.
3820 There are four levels of warning that GCC supports. The default is
3821 @option{-Wnormalized=nfc}, which warns about any identifier which is
3822 not in the ISO 10646 ``C'' normalized form, @dfn{NFC}. NFC is the
3823 recommended form for most uses.
3825 Unfortunately, there are some characters which ISO C and ISO C++ allow
3826 in identifiers that when turned into NFC aren't allowable as
3827 identifiers. That is, there's no way to use these symbols in portable
3828 ISO C or C++ and have all your identifiers in NFC@.
3829 @option{-Wnormalized=id} suppresses the warning for these characters.
3830 It is hoped that future versions of the standards involved will correct
3831 this, which is why this option is not the default.
3833 You can switch the warning off for all characters by writing
3834 @option{-Wnormalized=none}. You would only want to do this if you
3835 were using some other normalization scheme (like ``D''), because
3836 otherwise you can easily create bugs that are literally impossible to see.
3838 Some characters in ISO 10646 have distinct meanings but look identical
3839 in some fonts or display methodologies, especially once formatting has
3840 been applied. For instance @code{\u207F}, ``SUPERSCRIPT LATIN SMALL
3841 LETTER N'', will display just like a regular @code{n} which has been
3842 placed in a superscript. ISO 10646 defines the @dfn{NFKC}
3843 normalization scheme to convert all these into a standard form as
3844 well, and GCC will warn if your code is not in NFKC if you use
3845 @option{-Wnormalized=nfkc}. This warning is comparable to warning
3846 about every identifier that contains the letter O because it might be
3847 confused with the digit 0, and so is not the default, but may be
3848 useful as a local coding convention if the programming environment is
3849 unable to be fixed to display these characters distinctly.
3851 @item -Wno-deprecated-declarations
3852 @opindex Wno-deprecated-declarations
3853 @opindex Wdeprecated-declarations
3854 Do not warn about uses of functions (@pxref{Function Attributes}),
3855 variables (@pxref{Variable Attributes}), and types (@pxref{Type
3856 Attributes}) marked as deprecated by using the @code{deprecated}
3860 @opindex Wno-overflow
3862 Do not warn about compile-time overflow in constant expressions.
3864 @item -Woverride-init @r{(C and Objective-C only)}
3865 @opindex Woverride-init
3866 @opindex Wno-override-init
3870 Warn if an initialized field without side effects is overridden when
3871 using designated initializers (@pxref{Designated Inits, , Designated
3874 This warning is included in @option{-Wextra}. To get other
3875 @option{-Wextra} warnings without this one, use @samp{-Wextra
3876 -Wno-override-init}.
3881 Warn if a structure is given the packed attribute, but the packed
3882 attribute has no effect on the layout or size of the structure.
3883 Such structures may be mis-aligned for little benefit. For
3884 instance, in this code, the variable @code{f.x} in @code{struct bar}
3885 will be misaligned even though @code{struct bar} does not itself
3886 have the packed attribute:
3893 @} __attribute__((packed));
3904 Warn if padding is included in a structure, either to align an element
3905 of the structure or to align the whole structure. Sometimes when this
3906 happens it is possible to rearrange the fields of the structure to
3907 reduce the padding and so make the structure smaller.
3909 @item -Wredundant-decls
3910 @opindex Wredundant-decls
3911 @opindex Wno-redundant-decls
3912 Warn if anything is declared more than once in the same scope, even in
3913 cases where multiple declaration is valid and changes nothing.
3915 @item -Wnested-externs @r{(C and Objective-C only)}
3916 @opindex Wnested-externs
3917 @opindex Wno-nested-externs
3918 Warn if an @code{extern} declaration is encountered within a function.
3920 @item -Wunreachable-code
3921 @opindex Wunreachable-code
3922 @opindex Wno-unreachable-code
3923 Warn if the compiler detects that code will never be executed.
3925 This option is intended to warn when the compiler detects that at
3926 least a whole line of source code will never be executed, because
3927 some condition is never satisfied or because it is after a
3928 procedure that never returns.
3930 It is possible for this option to produce a warning even though there
3931 are circumstances under which part of the affected line can be executed,
3932 so care should be taken when removing apparently-unreachable code.
3934 For instance, when a function is inlined, a warning may mean that the
3935 line is unreachable in only one inlined copy of the function.
3937 This option is not made part of @option{-Wall} because in a debugging
3938 version of a program there is often substantial code which checks
3939 correct functioning of the program and is, hopefully, unreachable
3940 because the program does work. Another common use of unreachable
3941 code is to provide behavior which is selectable at compile-time.
3946 Warn if a function can not be inlined and it was declared as inline.
3947 Even with this option, the compiler will not warn about failures to
3948 inline functions declared in system headers.
3950 The compiler uses a variety of heuristics to determine whether or not
3951 to inline a function. For example, the compiler takes into account
3952 the size of the function being inlined and the amount of inlining
3953 that has already been done in the current function. Therefore,
3954 seemingly insignificant changes in the source program can cause the
3955 warnings produced by @option{-Winline} to appear or disappear.
3957 @item -Wno-invalid-offsetof @r{(C++ and Objective-C++ only)}
3958 @opindex Wno-invalid-offsetof
3959 @opindex Winvalid-offsetof
3960 Suppress warnings from applying the @samp{offsetof} macro to a non-POD
3961 type. According to the 1998 ISO C++ standard, applying @samp{offsetof}
3962 to a non-POD type is undefined. In existing C++ implementations,
3963 however, @samp{offsetof} typically gives meaningful results even when
3964 applied to certain kinds of non-POD types. (Such as a simple
3965 @samp{struct} that fails to be a POD type only by virtue of having a
3966 constructor.) This flag is for users who are aware that they are
3967 writing nonportable code and who have deliberately chosen to ignore the
3970 The restrictions on @samp{offsetof} may be relaxed in a future version
3971 of the C++ standard.
3973 @item -Wno-int-to-pointer-cast @r{(C and Objective-C only)}
3974 @opindex Wno-int-to-pointer-cast
3975 @opindex Wint-to-pointer-cast
3976 Suppress warnings from casts to pointer type of an integer of a
3979 @item -Wno-pointer-to-int-cast @r{(C and Objective-C only)}
3980 @opindex Wno-pointer-to-int-cast
3981 @opindex Wpointer-to-int-cast
3982 Suppress warnings from casts from a pointer to an integer type of a
3986 @opindex Winvalid-pch
3987 @opindex Wno-invalid-pch
3988 Warn if a precompiled header (@pxref{Precompiled Headers}) is found in
3989 the search path but can't be used.
3993 @opindex Wno-long-long
3994 Warn if @samp{long long} type is used. This is default. To inhibit
3995 the warning messages, use @option{-Wno-long-long}. Flags
3996 @option{-Wlong-long} and @option{-Wno-long-long} are taken into account
3997 only when @option{-pedantic} flag is used.
3999 @item -Wvariadic-macros
4000 @opindex Wvariadic-macros
4001 @opindex Wno-variadic-macros
4002 Warn if variadic macros are used in pedantic ISO C90 mode, or the GNU
4003 alternate syntax when in pedantic ISO C99 mode. This is default.
4004 To inhibit the warning messages, use @option{-Wno-variadic-macros}.
4009 Warn if variable length array is used in the code.
4010 @option{-Wno-vla} will prevent the @option{-pedantic} warning of
4011 the variable length array.
4013 @item -Wvolatile-register-var
4014 @opindex Wvolatile-register-var
4015 @opindex Wno-volatile-register-var
4016 Warn if a register variable is declared volatile. The volatile
4017 modifier does not inhibit all optimizations that may eliminate reads
4018 and/or writes to register variables.
4020 @item -Wdisabled-optimization
4021 @opindex Wdisabled-optimization
4022 @opindex Wno-disabled-optimization
4023 Warn if a requested optimization pass is disabled. This warning does
4024 not generally indicate that there is anything wrong with your code; it
4025 merely indicates that GCC's optimizers were unable to handle the code
4026 effectively. Often, the problem is that your code is too big or too
4027 complex; GCC will refuse to optimize programs when the optimization
4028 itself is likely to take inordinate amounts of time.
4030 @item -Wpointer-sign @r{(C and Objective-C only)}
4031 @opindex Wpointer-sign
4032 @opindex Wno-pointer-sign
4033 Warn for pointer argument passing or assignment with different signedness.
4034 This option is only supported for C and Objective-C@. It is implied by
4035 @option{-Wall} and by @option{-pedantic}, which can be disabled with
4036 @option{-Wno-pointer-sign}.
4038 @item -Wstack-protector
4039 @opindex Wstack-protector
4040 @opindex Wno-stack-protector
4041 This option is only active when @option{-fstack-protector} is active. It
4042 warns about functions that will not be protected against stack smashing.
4044 @item -Woverlength-strings
4045 @opindex Woverlength-strings
4046 @opindex Wno-overlength-strings
4047 Warn about string constants which are longer than the ``minimum
4048 maximum'' length specified in the C standard. Modern compilers
4049 generally allow string constants which are much longer than the
4050 standard's minimum limit, but very portable programs should avoid
4051 using longer strings.
4053 The limit applies @emph{after} string constant concatenation, and does
4054 not count the trailing NUL@. In C89, the limit was 509 characters; in
4055 C99, it was raised to 4095. C++98 does not specify a normative
4056 minimum maximum, so we do not diagnose overlength strings in C++@.
4058 This option is implied by @option{-pedantic}, and can be disabled with
4059 @option{-Wno-overlength-strings}.
4062 @node Debugging Options
4063 @section Options for Debugging Your Program or GCC
4064 @cindex options, debugging
4065 @cindex debugging information options
4067 GCC has various special options that are used for debugging
4068 either your program or GCC:
4073 Produce debugging information in the operating system's native format
4074 (stabs, COFF, XCOFF, or DWARF 2)@. GDB can work with this debugging
4077 On most systems that use stabs format, @option{-g} enables use of extra
4078 debugging information that only GDB can use; this extra information
4079 makes debugging work better in GDB but will probably make other debuggers
4081 refuse to read the program. If you want to control for certain whether
4082 to generate the extra information, use @option{-gstabs+}, @option{-gstabs},
4083 @option{-gxcoff+}, @option{-gxcoff}, or @option{-gvms} (see below).
4085 GCC allows you to use @option{-g} with
4086 @option{-O}. The shortcuts taken by optimized code may occasionally
4087 produce surprising results: some variables you declared may not exist
4088 at all; flow of control may briefly move where you did not expect it;
4089 some statements may not be executed because they compute constant
4090 results or their values were already at hand; some statements may
4091 execute in different places because they were moved out of loops.
4093 Nevertheless it proves possible to debug optimized output. This makes
4094 it reasonable to use the optimizer for programs that might have bugs.
4096 The following options are useful when GCC is generated with the
4097 capability for more than one debugging format.
4101 Produce debugging information for use by GDB@. This means to use the
4102 most expressive format available (DWARF 2, stabs, or the native format
4103 if neither of those are supported), including GDB extensions if at all
4108 Produce debugging information in stabs format (if that is supported),
4109 without GDB extensions. This is the format used by DBX on most BSD
4110 systems. On MIPS, Alpha and System V Release 4 systems this option
4111 produces stabs debugging output which is not understood by DBX or SDB@.
4112 On System V Release 4 systems this option requires the GNU assembler.
4114 @item -feliminate-unused-debug-symbols
4115 @opindex feliminate-unused-debug-symbols
4116 Produce debugging information in stabs format (if that is supported),
4117 for only symbols that are actually used.
4119 @item -femit-class-debug-always
4120 Instead of emitting debugging information for a C++ class in only one
4121 object file, emit it in all object files using the class. This option
4122 should be used only with debuggers that are unable to handle the way GCC
4123 normally emits debugging information for classes because using this
4124 option will increase the size of debugging information by as much as a
4129 Produce debugging information in stabs format (if that is supported),
4130 using GNU extensions understood only by the GNU debugger (GDB)@. The
4131 use of these extensions is likely to make other debuggers crash or
4132 refuse to read the program.
4136 Produce debugging information in COFF format (if that is supported).
4137 This is the format used by SDB on most System V systems prior to
4142 Produce debugging information in XCOFF format (if that is supported).
4143 This is the format used by the DBX debugger on IBM RS/6000 systems.
4147 Produce debugging information in XCOFF format (if that is supported),
4148 using GNU extensions understood only by the GNU debugger (GDB)@. The
4149 use of these extensions is likely to make other debuggers crash or
4150 refuse to read the program, and may cause assemblers other than the GNU
4151 assembler (GAS) to fail with an error.
4155 Produce debugging information in DWARF version 2 format (if that is
4156 supported). This is the format used by DBX on IRIX 6. With this
4157 option, GCC uses features of DWARF version 3 when they are useful;
4158 version 3 is upward compatible with version 2, but may still cause
4159 problems for older debuggers.
4163 Produce debugging information in VMS debug format (if that is
4164 supported). This is the format used by DEBUG on VMS systems.
4167 @itemx -ggdb@var{level}
4168 @itemx -gstabs@var{level}
4169 @itemx -gcoff@var{level}
4170 @itemx -gxcoff@var{level}
4171 @itemx -gvms@var{level}
4172 Request debugging information and also use @var{level} to specify how
4173 much information. The default level is 2.
4175 Level 0 produces no debug information at all. Thus, @option{-g0} negates
4178 Level 1 produces minimal information, enough for making backtraces in
4179 parts of the program that you don't plan to debug. This includes
4180 descriptions of functions and external variables, but no information
4181 about local variables and no line numbers.
4183 Level 3 includes extra information, such as all the macro definitions
4184 present in the program. Some debuggers support macro expansion when
4185 you use @option{-g3}.
4187 @option{-gdwarf-2} does not accept a concatenated debug level, because
4188 GCC used to support an option @option{-gdwarf} that meant to generate
4189 debug information in version 1 of the DWARF format (which is very
4190 different from version 2), and it would have been too confusing. That
4191 debug format is long obsolete, but the option cannot be changed now.
4192 Instead use an additional @option{-g@var{level}} option to change the
4193 debug level for DWARF2.
4195 @item -feliminate-dwarf2-dups
4196 @opindex feliminate-dwarf2-dups
4197 Compress DWARF2 debugging information by eliminating duplicated
4198 information about each symbol. This option only makes sense when
4199 generating DWARF2 debugging information with @option{-gdwarf-2}.
4201 @item -femit-struct-debug-baseonly
4202 Emit debug information for struct-like types
4203 only when the base name of the compilation source file
4204 matches the base name of file in which the struct was defined.
4206 This option substantially reduces the size of debugging information,
4207 but at significant potential loss in type information to the debugger.
4208 See @option{-femit-struct-debug-reduced} for a less aggressive option.
4209 See @option{-femit-struct-debug-detailed} for more detailed control.
4211 This option works only with DWARF 2.
4213 @item -femit-struct-debug-reduced
4214 Emit debug information for struct-like types
4215 only when the base name of the compilation source file
4216 matches the base name of file in which the type was defined,
4217 unless the struct is a template or defined in a system header.
4219 This option significantly reduces the size of debugging information,
4220 with some potential loss in type information to the debugger.
4221 See @option{-femit-struct-debug-baseonly} for a more aggressive option.
4222 See @option{-femit-struct-debug-detailed} for more detailed control.
4224 This option works only with DWARF 2.
4226 @item -femit-struct-debug-detailed@r{[}=@var{spec-list}@r{]}
4227 Specify the struct-like types
4228 for which the compiler will generate debug information.
4229 The intent is to reduce duplicate struct debug information
4230 between different object files within the same program.
4232 This option is a detailed version of
4233 @option{-femit-struct-debug-reduced} and @option{-femit-struct-debug-baseonly},
4234 which will serve for most needs.
4236 A specification has the syntax
4237 [@samp{dir:}|@samp{ind:}][@samp{ord:}|@samp{gen:}](@samp{any}|@samp{sys}|@samp{base}|@samp{none})
4239 The optional first word limits the specification to
4240 structs that are used directly (@samp{dir:}) or used indirectly (@samp{ind:}).
4241 A struct type is used directly when it is the type of a variable, member.
4242 Indirect uses arise through pointers to structs.
4243 That is, when use of an incomplete struct would be legal, the use is indirect.
4245 @samp{struct one direct; struct two * indirect;}.
4247 The optional second word limits the specification to
4248 ordinary structs (@samp{ord:}) or generic structs (@samp{gen:}).
4249 Generic structs are a bit complicated to explain.
4250 For C++, these are non-explicit specializations of template classes,
4251 or non-template classes within the above.
4252 Other programming languages have generics,
4253 but @samp{-femit-struct-debug-detailed} does not yet implement them.
4255 The third word specifies the source files for those
4256 structs for which the compiler will emit debug information.
4257 The values @samp{none} and @samp{any} have the normal meaning.
4258 The value @samp{base} means that
4259 the base of name of the file in which the type declaration appears
4260 must match the base of the name of the main compilation file.
4261 In practice, this means that
4262 types declared in @file{foo.c} and @file{foo.h} will have debug information,
4263 but types declared in other header will not.
4264 The value @samp{sys} means those types satisfying @samp{base}
4265 or declared in system or compiler headers.
4267 You may need to experiment to determine the best settings for your application.
4269 The default is @samp{-femit-struct-debug-detailed=all}.
4271 This option works only with DWARF 2.