1 @c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2 @c 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
3 @c This is part of the GCC manual.
4 @c For copying conditions, see the file gcc.texi.
11 @c man begin COPYRIGHT
12 Copyright @copyright{} 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
13 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
15 Permission is granted to copy, distribute and/or modify this document
16 under the terms of the GNU Free Documentation License, Version 1.2 or
17 any later version published by the Free Software Foundation; with the
18 Invariant Sections being ``GNU General Public License'' and ``Funding
19 Free Software'', the Front-Cover texts being (a) (see below), and with
20 the Back-Cover Texts being (b) (see below). A copy of the license is
21 included in the gfdl(7) man page.
23 (a) The FSF's Front-Cover Text is:
27 (b) The FSF's Back-Cover Text is:
29 You have freedom to copy and modify this GNU Manual, like GNU
30 software. Copies published by the Free Software Foundation raise
31 funds for GNU development.
33 @c Set file name and title for the man page.
35 @settitle GNU project C and C++ compiler
37 gcc [@option{-c}|@option{-S}|@option{-E}] [@option{-std=}@var{standard}]
38 [@option{-g}] [@option{-pg}] [@option{-O}@var{level}]
39 [@option{-W}@var{warn}@dots{}] [@option{-pedantic}]
40 [@option{-I}@var{dir}@dots{}] [@option{-L}@var{dir}@dots{}]
41 [@option{-D}@var{macro}[=@var{defn}]@dots{}] [@option{-U}@var{macro}]
42 [@option{-f}@var{option}@dots{}] [@option{-m}@var{machine-option}@dots{}]
43 [@option{-o} @var{outfile}] [@@@var{file}] @var{infile}@dots{}
45 Only the most useful options are listed here; see below for the
46 remainder. @samp{g++} accepts mostly the same options as @samp{gcc}.
49 gpl(7), gfdl(7), fsf-funding(7),
50 cpp(1), gcov(1), as(1), ld(1), gdb(1), adb(1), dbx(1), sdb(1)
51 and the Info entries for @file{gcc}, @file{cpp}, @file{as},
52 @file{ld}, @file{binutils} and @file{gdb}.
55 For instructions on reporting bugs, see
56 @w{@uref{http://gcc.gnu.org/bugs.html}}.
59 See the Info entry for @command{gcc}, or
60 @w{@uref{http://gcc.gnu.org/onlinedocs/gcc/Contributors.html}},
61 for contributors to GCC@.
66 @chapter GCC Command Options
67 @cindex GCC command options
68 @cindex command options
69 @cindex options, GCC command
71 @c man begin DESCRIPTION
72 When you invoke GCC, it normally does preprocessing, compilation,
73 assembly and linking. The ``overall options'' allow you to stop this
74 process at an intermediate stage. For example, the @option{-c} option
75 says not to run the linker. Then the output consists of object files
76 output by the assembler.
78 Other options are passed on to one stage of processing. Some options
79 control the preprocessor and others the compiler itself. Yet other
80 options control the assembler and linker; most of these are not
81 documented here, since you rarely need to use any of them.
83 @cindex C compilation options
84 Most of the command line options that you can use with GCC are useful
85 for C programs; when an option is only useful with another language
86 (usually C++), the explanation says so explicitly. If the description
87 for a particular option does not mention a source language, you can use
88 that option with all supported languages.
90 @cindex C++ compilation options
91 @xref{Invoking G++,,Compiling C++ Programs}, for a summary of special
92 options for compiling C++ programs.
94 @cindex grouping options
95 @cindex options, grouping
96 The @command{gcc} program accepts options and file names as operands. Many
97 options have multi-letter names; therefore multiple single-letter options
98 may @emph{not} be grouped: @option{-dr} is very different from @w{@samp{-d
101 @cindex order of options
102 @cindex options, order
103 You can mix options and other arguments. For the most part, the order
104 you use doesn't matter. Order does matter when you use several options
105 of the same kind; for example, if you specify @option{-L} more than once,
106 the directories are searched in the order specified.
108 Many options have long names starting with @samp{-f} or with
109 @samp{-W}---for example,
110 @option{-fmove-loop-invariants}, @option{-Wformat} and so on. Most of
111 these have both positive and negative forms; the negative form of
112 @option{-ffoo} would be @option{-fno-foo}. This manual documents
113 only one of these two forms, whichever one is not the default.
117 @xref{Option Index}, for an index to GCC's options.
120 * Option Summary:: Brief list of all options, without explanations.
121 * Overall Options:: Controlling the kind of output:
122 an executable, object files, assembler files,
123 or preprocessed source.
124 * Invoking G++:: Compiling C++ programs.
125 * C Dialect Options:: Controlling the variant of C language compiled.
126 * C++ Dialect Options:: Variations on C++.
127 * Objective-C and Objective-C++ Dialect Options:: Variations on Objective-C
129 * Language Independent Options:: Controlling how diagnostics should be
131 * Warning Options:: How picky should the compiler be?
132 * Debugging Options:: Symbol tables, measurements, and debugging dumps.
133 * Optimize Options:: How much optimization?
134 * Preprocessor Options:: Controlling header files and macro definitions.
135 Also, getting dependency information for Make.
136 * Assembler Options:: Passing options to the assembler.
137 * Link Options:: Specifying libraries and so on.
138 * Directory Options:: Where to find header files and libraries.
139 Where to find the compiler executable files.
140 * Spec Files:: How to pass switches to sub-processes.
141 * Target Options:: Running a cross-compiler, or an old version of GCC.
142 * Submodel Options:: Specifying minor hardware or convention variations,
143 such as 68010 vs 68020.
144 * Code Gen Options:: Specifying conventions for function calls, data layout
146 * Environment Variables:: Env vars that affect GCC.
147 * Precompiled Headers:: Compiling a header once, and using it many times.
148 * Running Protoize:: Automatically adding or removing function prototypes.
154 @section Option Summary
156 Here is a summary of all the options, grouped by type. Explanations are
157 in the following sections.
160 @item Overall Options
161 @xref{Overall Options,,Options Controlling the Kind of Output}.
162 @gccoptlist{-c -S -E -o @var{file} -combine -pipe -pass-exit-codes @gol
163 -x @var{language} -v -### --help --target-help --version @@@var{file}}
165 @item C Language Options
166 @xref{C Dialect Options,,Options Controlling C Dialect}.
167 @gccoptlist{-ansi -std=@var{standard} -aux-info @var{filename} @gol
168 -fno-asm -fno-builtin -fno-builtin-@var{function} @gol
169 -fhosted -ffreestanding -fopenmp -fms-extensions @gol
170 -trigraphs -no-integrated-cpp -traditional -traditional-cpp @gol
171 -fallow-single-precision -fcond-mismatch @gol
172 -fsigned-bitfields -fsigned-char @gol
173 -funsigned-bitfields -funsigned-char}
175 @item C++ Language Options
176 @xref{C++ Dialect Options,,Options Controlling C++ Dialect}.
177 @gccoptlist{-fabi-version=@var{n} -fno-access-control -fcheck-new @gol
178 -fconserve-space -ffriend-injection @gol
179 -fno-elide-constructors @gol
180 -fno-enforce-eh-specs @gol
181 -ffor-scope -fno-for-scope -fno-gnu-keywords @gol
182 -fno-implicit-templates @gol
183 -fno-implicit-inline-templates @gol
184 -fno-implement-inlines -fms-extensions @gol
185 -fno-nonansi-builtins -fno-operator-names @gol
186 -fno-optional-diags -fpermissive @gol
187 -frepo -fno-rtti -fstats -ftemplate-depth-@var{n} @gol
188 -fno-threadsafe-statics -fuse-cxa-atexit -fno-weak -nostdinc++ @gol
189 -fno-default-inline -fvisibility-inlines-hidden @gol
190 -Wabi -Wctor-dtor-privacy @gol
191 -Wnon-virtual-dtor -Wreorder @gol
192 -Weffc++ -Wno-deprecated -Wstrict-null-sentinel @gol
193 -Wno-non-template-friend -Wold-style-cast @gol
194 -Woverloaded-virtual -Wno-pmf-conversions @gol
197 @item Objective-C and Objective-C++ Language Options
198 @xref{Objective-C and Objective-C++ Dialect Options,,Options Controlling
199 Objective-C and Objective-C++ Dialects}.
201 -fconstant-string-class=@var{class-name} @gol
202 -fgnu-runtime -fnext-runtime @gol
203 -fno-nil-receivers @gol
204 -fobjc-call-cxx-cdtors @gol
205 -fobjc-direct-dispatch @gol
206 -fobjc-exceptions @gol
208 -freplace-objc-classes @gol
211 -Wassign-intercept @gol
212 -Wno-protocol -Wselector @gol
213 -Wstrict-selector-match @gol
214 -Wundeclared-selector}
216 @item Language Independent Options
217 @xref{Language Independent Options,,Options to Control Diagnostic Messages Formatting}.
218 @gccoptlist{-fmessage-length=@var{n} @gol
219 -fdiagnostics-show-location=@r{[}once@r{|}every-line@r{]}} @gol
220 -fdiagnostics-show-option
222 @item Warning Options
223 @xref{Warning Options,,Options to Request or Suppress Warnings}.
224 @gccoptlist{-fsyntax-only -pedantic -pedantic-errors @gol
225 -w -Wextra -Wall -Waggregate-return -Walways-true -Wno-attributes @gol
226 -Wc++-compat -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment @gol
227 -Wconversion -Wno-deprecated-declarations @gol
228 -Wdisabled-optimization -Wno-div-by-zero -Wno-endif-labels @gol
229 -Werror -Werror-* -Werror-implicit-function-declaration @gol
230 -Wfatal-errors -Wfloat-equal -Wformat -Wformat=2 @gol
231 -Wno-format-extra-args -Wformat-nonliteral @gol
232 -Wformat-security -Wformat-y2k @gol
233 -Wimplicit -Wimplicit-function-declaration -Wimplicit-int @gol
234 -Wimport -Wno-import -Winit-self -Winline @gol
235 -Wno-int-to-pointer-cast @gol
236 -Wno-invalid-offsetof -Winvalid-pch @gol
237 -Wlarger-than-@var{len} -Wunsafe-loop-optimizations -Wlong-long @gol
238 -Wmain -Wmissing-braces -Wmissing-field-initializers @gol
239 -Wmissing-format-attribute -Wmissing-include-dirs @gol
240 -Wmissing-noreturn @gol
241 -Wno-multichar -Wnonnull -Wno-overflow @gol
242 -Woverlength-strings -Wpacked -Wpadded @gol
243 -Wparentheses -Wpointer-arith -Wno-pointer-to-int-cast @gol
244 -Wredundant-decls @gol
245 -Wreturn-type -Wsequence-point -Wshadow @gol
246 -Wsign-compare -Wstack-protector @gol
247 -Wstrict-aliasing -Wstrict-aliasing=2 @gol
248 -Wstring-literal-comparison @gol
249 -Wswitch -Wswitch-default -Wswitch-enum @gol
250 -Wsystem-headers -Wtrigraphs -Wundef -Wuninitialized @gol
251 -Wunknown-pragmas -Wno-pragmas -Wunreachable-code @gol
252 -Wunused -Wunused-function -Wunused-label -Wunused-parameter @gol
253 -Wunused-value -Wunused-variable -Wvariadic-macros @gol
254 -Wvolatile-register-var -Wwrite-strings}
256 @item C-only Warning Options
257 @gccoptlist{-Wbad-function-cast -Wmissing-declarations @gol
258 -Wmissing-prototypes -Wnested-externs -Wold-style-definition @gol
259 -Wstrict-prototypes -Wtraditional @gol
260 -Wdeclaration-after-statement -Wpointer-sign}
262 @item Debugging Options
263 @xref{Debugging Options,,Options for Debugging Your Program or GCC}.
264 @gccoptlist{-d@var{letters} -dumpspecs -dumpmachine -dumpversion @gol
265 -fdump-noaddr -fdump-unnumbered -fdump-translation-unit@r{[}-@var{n}@r{]} @gol
266 -fdump-class-hierarchy@r{[}-@var{n}@r{]} @gol
267 -fdump-ipa-all -fdump-ipa-cgraph @gol
269 -fdump-tree-original@r{[}-@var{n}@r{]} @gol
270 -fdump-tree-optimized@r{[}-@var{n}@r{]} @gol
271 -fdump-tree-inlined@r{[}-@var{n}@r{]} @gol
272 -fdump-tree-cfg -fdump-tree-vcg -fdump-tree-alias @gol
274 -fdump-tree-ssa@r{[}-@var{n}@r{]} -fdump-tree-pre@r{[}-@var{n}@r{]} @gol
275 -fdump-tree-ccp@r{[}-@var{n}@r{]} -fdump-tree-dce@r{[}-@var{n}@r{]} @gol
276 -fdump-tree-gimple@r{[}-raw@r{]} -fdump-tree-mudflap@r{[}-@var{n}@r{]} @gol
277 -fdump-tree-dom@r{[}-@var{n}@r{]} @gol
278 -fdump-tree-dse@r{[}-@var{n}@r{]} @gol
279 -fdump-tree-phiopt@r{[}-@var{n}@r{]} @gol
280 -fdump-tree-forwprop@r{[}-@var{n}@r{]} @gol
281 -fdump-tree-copyrename@r{[}-@var{n}@r{]} @gol
282 -fdump-tree-nrv -fdump-tree-vect @gol
283 -fdump-tree-sink @gol
284 -fdump-tree-sra@r{[}-@var{n}@r{]} @gol
285 -fdump-tree-salias @gol
286 -fdump-tree-fre@r{[}-@var{n}@r{]} @gol
287 -fdump-tree-vrp@r{[}-@var{n}@r{]} @gol
288 -ftree-vectorizer-verbose=@var{n} @gol
289 -fdump-tree-storeccp@r{[}-@var{n}@r{]} @gol
290 -feliminate-dwarf2-dups -feliminate-unused-debug-types @gol
291 -feliminate-unused-debug-symbols -femit-class-debug-always @gol
292 -fmem-report -fprofile-arcs @gol
293 -frandom-seed=@var{string} -fsched-verbose=@var{n} @gol
294 -ftest-coverage -ftime-report -fvar-tracking @gol
295 -g -g@var{level} -gcoff -gdwarf-2 @gol
296 -ggdb -gstabs -gstabs+ -gvms -gxcoff -gxcoff+ @gol
297 -p -pg -print-file-name=@var{library} -print-libgcc-file-name @gol
298 -print-multi-directory -print-multi-lib @gol
299 -print-prog-name=@var{program} -print-search-dirs -Q @gol
302 @item Optimization Options
303 @xref{Optimize Options,,Options that Control Optimization}.
304 @gccoptlist{-falign-functions=@var{n} -falign-jumps=@var{n} @gol
305 -falign-labels=@var{n} -falign-loops=@var{n} @gol
306 -fbounds-check -fmudflap -fmudflapth -fmudflapir @gol
307 -fbranch-probabilities -fprofile-values -fvpt -fbranch-target-load-optimize @gol
308 -fbranch-target-load-optimize2 -fbtr-bb-exclusive @gol
309 -fcaller-saves -fcprop-registers -fcse-follow-jumps @gol
310 -fcse-skip-blocks -fcx-limited-range -fdata-sections @gol
311 -fdelayed-branch -fdelete-null-pointer-checks -fearly-inlining @gol
312 -fexpensive-optimizations -ffast-math -ffloat-store @gol
313 -fforce-addr -ffunction-sections @gol
314 -fgcse -fgcse-lm -fgcse-sm -fgcse-las -fgcse-after-reload @gol
315 -fcrossjumping -fif-conversion -fif-conversion2 @gol
316 -finline-functions -finline-functions-called-once @gol
317 -finline-limit=@var{n} -fkeep-inline-functions @gol
318 -fkeep-static-consts -fmerge-constants -fmerge-all-constants @gol
319 -fmodulo-sched -fno-branch-count-reg @gol
320 -fno-default-inline -fno-defer-pop -fmove-loop-invariants @gol
321 -fno-function-cse -fno-guess-branch-probability @gol
322 -fno-inline -fno-math-errno -fno-peephole -fno-peephole2 @gol
323 -funsafe-math-optimizations -funsafe-loop-optimizations -ffinite-math-only @gol
324 -fno-toplevel-reorder -fno-trapping-math -fno-zero-initialized-in-bss @gol
325 -fomit-frame-pointer -foptimize-register-move @gol
326 -foptimize-sibling-calls -fprefetch-loop-arrays @gol
327 -fprofile-generate -fprofile-use @gol
328 -fregmove -frename-registers @gol
329 -freorder-blocks -freorder-blocks-and-partition -freorder-functions @gol
330 -frerun-cse-after-loop @gol
331 -frounding-math -frtl-abstract-sequences @gol
332 -fschedule-insns -fschedule-insns2 @gol
333 -fno-sched-interblock -fno-sched-spec -fsched-spec-load @gol
334 -fsched-spec-load-dangerous @gol
335 -fsched-stalled-insns=@var{n} -fsched-stalled-insns-dep=@var{n} @gol
336 -fsched2-use-superblocks @gol
337 -fsched2-use-traces -fsee -freschedule-modulo-scheduled-loops @gol
338 -fsection-anchors -fsignaling-nans -fsingle-precision-constant @gol
339 -fstack-protector -fstack-protector-all @gol
340 -fstrict-aliasing -ftracer -fthread-jumps @gol
341 -funroll-all-loops -funroll-loops -fpeel-loops @gol
342 -fsplit-ivs-in-unroller -funswitch-loops @gol
343 -fvariable-expansion-in-unroller @gol
344 -ftree-pre -ftree-ccp -ftree-dce -ftree-loop-optimize @gol
345 -ftree-loop-linear -ftree-loop-im -ftree-loop-ivcanon -fivopts @gol
346 -ftree-dominator-opts -ftree-dse -ftree-copyrename -ftree-sink @gol
347 -ftree-ch -ftree-sra -ftree-ter -ftree-lrs -ftree-fre -ftree-vectorize @gol
348 -ftree-vect-loop-version -ftree-salias -fipa-pta -fweb @gol
349 -ftree-copy-prop -ftree-store-ccp -ftree-store-copy-prop -fwhole-program @gol
350 --param @var{name}=@var{value}
351 -O -O0 -O1 -O2 -O3 -Os}
353 @item Preprocessor Options
354 @xref{Preprocessor Options,,Options Controlling the Preprocessor}.
355 @gccoptlist{-A@var{question}=@var{answer} @gol
356 -A-@var{question}@r{[}=@var{answer}@r{]} @gol
357 -C -dD -dI -dM -dN @gol
358 -D@var{macro}@r{[}=@var{defn}@r{]} -E -H @gol
359 -idirafter @var{dir} @gol
360 -include @var{file} -imacros @var{file} @gol
361 -iprefix @var{file} -iwithprefix @var{dir} @gol
362 -iwithprefixbefore @var{dir} -isystem @var{dir} @gol
363 -imultilib @var{dir} -isysroot @var{dir} @gol
364 -M -MM -MF -MG -MP -MQ -MT -nostdinc @gol
365 -P -fworking-directory -remap @gol
366 -trigraphs -undef -U@var{macro} -Wp,@var{option} @gol
367 -Xpreprocessor @var{option}}
369 @item Assembler Option
370 @xref{Assembler Options,,Passing Options to the Assembler}.
371 @gccoptlist{-Wa,@var{option} -Xassembler @var{option}}
374 @xref{Link Options,,Options for Linking}.
375 @gccoptlist{@var{object-file-name} -l@var{library} @gol
376 -nostartfiles -nodefaultlibs -nostdlib -pie -rdynamic @gol
377 -s -static -static-libgcc -shared -shared-libgcc -symbolic @gol
378 -Wl,@var{option} -Xlinker @var{option} @gol
381 @item Directory Options
382 @xref{Directory Options,,Options for Directory Search}.
383 @gccoptlist{-B@var{prefix} -I@var{dir} -iquote@var{dir} -L@var{dir}
384 -specs=@var{file} -I- --sysroot=@var{dir}}
387 @c I wrote this xref this way to avoid overfull hbox. -- rms
388 @xref{Target Options}.
389 @gccoptlist{-V @var{version} -b @var{machine}}
391 @item Machine Dependent Options
392 @xref{Submodel Options,,Hardware Models and Configurations}.
393 @c This list is ordered alphanumerically by subsection name.
394 @c Try and put the significant identifier (CPU or system) first,
395 @c so users have a clue at guessing where the ones they want will be.
398 @gccoptlist{-EB -EL @gol
399 -mmangle-cpu -mcpu=@var{cpu} -mtext=@var{text-section} @gol
400 -mdata=@var{data-section} -mrodata=@var{readonly-data-section}}
403 @gccoptlist{-mapcs-frame -mno-apcs-frame @gol
404 -mabi=@var{name} @gol
405 -mapcs-stack-check -mno-apcs-stack-check @gol
406 -mapcs-float -mno-apcs-float @gol
407 -mapcs-reentrant -mno-apcs-reentrant @gol
408 -msched-prolog -mno-sched-prolog @gol
409 -mlittle-endian -mbig-endian -mwords-little-endian @gol
410 -mfloat-abi=@var{name} -msoft-float -mhard-float -mfpe @gol
411 -mthumb-interwork -mno-thumb-interwork @gol
412 -mcpu=@var{name} -march=@var{name} -mfpu=@var{name} @gol
413 -mstructure-size-boundary=@var{n} @gol
414 -mabort-on-noreturn @gol
415 -mlong-calls -mno-long-calls @gol
416 -msingle-pic-base -mno-single-pic-base @gol
417 -mpic-register=@var{reg} @gol
418 -mnop-fun-dllimport @gol
419 -mcirrus-fix-invalid-insns -mno-cirrus-fix-invalid-insns @gol
420 -mpoke-function-name @gol
422 -mtpcs-frame -mtpcs-leaf-frame @gol
423 -mcaller-super-interworking -mcallee-super-interworking @gol
427 @gccoptlist{-mmcu=@var{mcu} -msize -minit-stack=@var{n} -mno-interrupts @gol
428 -mcall-prologues -mno-tablejump -mtiny-stack -mint8}
430 @emph{Blackfin Options}
431 @gccoptlist{-momit-leaf-frame-pointer -mno-omit-leaf-frame-pointer @gol
432 -mspecld-anomaly -mno-specld-anomaly -mcsync-anomaly -mno-csync-anomaly @gol
433 -mlow-64k -mno-low64k -mid-shared-library @gol
434 -mno-id-shared-library -mshared-library-id=@var{n} @gol
435 -mlong-calls -mno-long-calls}
438 @gccoptlist{-mcpu=@var{cpu} -march=@var{cpu} -mtune=@var{cpu} @gol
439 -mmax-stack-frame=@var{n} -melinux-stacksize=@var{n} @gol
440 -metrax4 -metrax100 -mpdebug -mcc-init -mno-side-effects @gol
441 -mstack-align -mdata-align -mconst-align @gol
442 -m32-bit -m16-bit -m8-bit -mno-prologue-epilogue -mno-gotplt @gol
443 -melf -maout -melinux -mlinux -sim -sim2 @gol
444 -mmul-bug-workaround -mno-mul-bug-workaround}
447 @gccoptlist{-mmac -mpush-args}
449 @emph{Darwin Options}
450 @gccoptlist{-all_load -allowable_client -arch -arch_errors_fatal @gol
451 -arch_only -bind_at_load -bundle -bundle_loader @gol
452 -client_name -compatibility_version -current_version @gol
454 -dependency-file -dylib_file -dylinker_install_name @gol
455 -dynamic -dynamiclib -exported_symbols_list @gol
456 -filelist -flat_namespace -force_cpusubtype_ALL @gol
457 -force_flat_namespace -headerpad_max_install_names @gol
458 -image_base -init -install_name -keep_private_externs @gol
459 -multi_module -multiply_defined -multiply_defined_unused @gol
460 -noall_load -no_dead_strip_inits_and_terms @gol
461 -nofixprebinding -nomultidefs -noprebind -noseglinkedit @gol
462 -pagezero_size -prebind -prebind_all_twolevel_modules @gol
463 -private_bundle -read_only_relocs -sectalign @gol
464 -sectobjectsymbols -whyload -seg1addr @gol
465 -sectcreate -sectobjectsymbols -sectorder @gol
466 -segaddr -segs_read_only_addr -segs_read_write_addr @gol
467 -seg_addr_table -seg_addr_table_filename -seglinkedit @gol
468 -segprot -segs_read_only_addr -segs_read_write_addr @gol
469 -single_module -static -sub_library -sub_umbrella @gol
470 -twolevel_namespace -umbrella -undefined @gol
471 -unexported_symbols_list -weak_reference_mismatches @gol
472 -whatsloaded -F -gused -gfull -mmacosx-version-min=@var{version} @gol
473 -mkernel -mone-byte-bool}
475 @emph{DEC Alpha Options}
476 @gccoptlist{-mno-fp-regs -msoft-float -malpha-as -mgas @gol
477 -mieee -mieee-with-inexact -mieee-conformant @gol
478 -mfp-trap-mode=@var{mode} -mfp-rounding-mode=@var{mode} @gol
479 -mtrap-precision=@var{mode} -mbuild-constants @gol
480 -mcpu=@var{cpu-type} -mtune=@var{cpu-type} @gol
481 -mbwx -mmax -mfix -mcix @gol
482 -mfloat-vax -mfloat-ieee @gol
483 -mexplicit-relocs -msmall-data -mlarge-data @gol
484 -msmall-text -mlarge-text @gol
485 -mmemory-latency=@var{time}}
487 @emph{DEC Alpha/VMS Options}
488 @gccoptlist{-mvms-return-codes}
491 @gccoptlist{-mgpr-32 -mgpr-64 -mfpr-32 -mfpr-64 @gol
492 -mhard-float -msoft-float @gol
493 -malloc-cc -mfixed-cc -mdword -mno-dword @gol
494 -mdouble -mno-double @gol
495 -mmedia -mno-media -mmuladd -mno-muladd @gol
496 -mfdpic -minline-plt -mgprel-ro -multilib-library-pic @gol
497 -mlinked-fp -mlong-calls -malign-labels @gol
498 -mlibrary-pic -macc-4 -macc-8 @gol
499 -mpack -mno-pack -mno-eflags -mcond-move -mno-cond-move @gol
500 -moptimize-membar -mno-optimize-membar @gol
501 -mscc -mno-scc -mcond-exec -mno-cond-exec @gol
502 -mvliw-branch -mno-vliw-branch @gol
503 -mmulti-cond-exec -mno-multi-cond-exec -mnested-cond-exec @gol
504 -mno-nested-cond-exec -mtomcat-stats @gol
508 @emph{GNU/Linux Options}
509 @gccoptlist{-muclibc}
511 @emph{H8/300 Options}
512 @gccoptlist{-mrelax -mh -ms -mn -mint32 -malign-300}
515 @gccoptlist{-march=@var{architecture-type} @gol
516 -mbig-switch -mdisable-fpregs -mdisable-indexing @gol
517 -mfast-indirect-calls -mgas -mgnu-ld -mhp-ld @gol
518 -mfixed-range=@var{register-range} @gol
519 -mjump-in-delay -mlinker-opt -mlong-calls @gol
520 -mlong-load-store -mno-big-switch -mno-disable-fpregs @gol
521 -mno-disable-indexing -mno-fast-indirect-calls -mno-gas @gol
522 -mno-jump-in-delay -mno-long-load-store @gol
523 -mno-portable-runtime -mno-soft-float @gol
524 -mno-space-regs -msoft-float -mpa-risc-1-0 @gol
525 -mpa-risc-1-1 -mpa-risc-2-0 -mportable-runtime @gol
526 -mschedule=@var{cpu-type} -mspace-regs -msio -mwsio @gol
527 -munix=@var{unix-std} -nolibdld -static -threads}
529 @emph{i386 and x86-64 Options}
530 @gccoptlist{-mtune=@var{cpu-type} -march=@var{cpu-type} @gol
531 -mfpmath=@var{unit} @gol
532 -masm=@var{dialect} -mno-fancy-math-387 @gol
533 -mno-fp-ret-in-387 -msoft-float -msvr3-shlib @gol
534 -mno-wide-multiply -mrtd -malign-double @gol
535 -mpreferred-stack-boundary=@var{num} @gol
536 -mmmx -msse -msse2 -msse3 -mssse3 -m3dnow @gol
537 -mthreads -mno-align-stringops -minline-all-stringops @gol
538 -mpush-args -maccumulate-outgoing-args -m128bit-long-double @gol
539 -m96bit-long-double -mregparm=@var{num} -msseregparm @gol
541 -momit-leaf-frame-pointer -mno-red-zone -mno-tls-direct-seg-refs @gol
542 -mcmodel=@var{code-model} @gol
543 -m32 -m64 -mlarge-data-threshold=@var{num}}
546 @gccoptlist{-mbig-endian -mlittle-endian -mgnu-as -mgnu-ld -mno-pic @gol
547 -mvolatile-asm-stop -mregister-names -mno-sdata @gol
548 -mconstant-gp -mauto-pic -minline-float-divide-min-latency @gol
549 -minline-float-divide-max-throughput @gol
550 -minline-int-divide-min-latency @gol
551 -minline-int-divide-max-throughput @gol
552 -minline-sqrt-min-latency -minline-sqrt-max-throughput @gol
553 -mno-dwarf2-asm -mearly-stop-bits @gol
554 -mfixed-range=@var{register-range} -mtls-size=@var{tls-size} @gol
555 -mtune=@var{cpu-type} -mt -pthread -milp32 -mlp64 @gol
556 -mno-sched-br-data-spec -msched-ar-data-spec -mno-sched-control-spec @gol
557 -msched-br-in-data-spec -msched-ar-in-data-spec -msched-in-control-spec @gol
558 -msched-ldc -mno-sched-control-ldc -mno-sched-spec-verbose @gol
559 -mno-sched-prefer-non-data-spec-insns @gol
560 -mno-sched-prefer-non-control-spec-insns @gol
561 -mno-sched-count-spec-in-critical-path}
563 @emph{M32R/D Options}
564 @gccoptlist{-m32r2 -m32rx -m32r @gol
566 -malign-loops -mno-align-loops @gol
567 -missue-rate=@var{number} @gol
568 -mbranch-cost=@var{number} @gol
569 -mmodel=@var{code-size-model-type} @gol
570 -msdata=@var{sdata-type} @gol
571 -mno-flush-func -mflush-func=@var{name} @gol
572 -mno-flush-trap -mflush-trap=@var{number} @gol
576 @gccoptlist{-mcpu=@var{cpu} -msim -memregs=@var{number}}
578 @emph{M680x0 Options}
579 @gccoptlist{-m68000 -m68020 -m68020-40 -m68020-60 -m68030 -m68040 @gol
580 -m68060 -mcpu32 -m5200 -mcfv4e -m68881 -mbitfield @gol
581 -mc68000 -mc68020 @gol
582 -mnobitfield -mrtd -mshort -msoft-float -mpcrel @gol
583 -malign-int -mstrict-align -msep-data -mno-sep-data @gol
584 -mshared-library-id=n -mid-shared-library -mno-id-shared-library}
586 @emph{M68hc1x Options}
587 @gccoptlist{-m6811 -m6812 -m68hc11 -m68hc12 -m68hcs12 @gol
588 -mauto-incdec -minmax -mlong-calls -mshort @gol
589 -msoft-reg-count=@var{count}}
592 @gccoptlist{-mhardlit -mno-hardlit -mdiv -mno-div -mrelax-immediates @gol
593 -mno-relax-immediates -mwide-bitfields -mno-wide-bitfields @gol
594 -m4byte-functions -mno-4byte-functions -mcallgraph-data @gol
595 -mno-callgraph-data -mslow-bytes -mno-slow-bytes -mno-lsim @gol
596 -mlittle-endian -mbig-endian -m210 -m340 -mstack-increment}
599 @gccoptlist{-EL -EB -march=@var{arch} -mtune=@var{arch} @gol
600 -mips1 -mips2 -mips3 -mips4 -mips32 -mips32r2 -mips64 @gol
601 -mips16 -mno-mips16 -mabi=@var{abi} -mabicalls -mno-abicalls @gol
602 -mshared -mno-shared -mxgot -mno-xgot -mgp32 -mgp64 @gol
603 -mfp32 -mfp64 -mhard-float -msoft-float @gol
604 -msingle-float -mdouble-float -mdsp -mpaired-single -mips3d @gol
605 -mlong64 -mlong32 -msym32 -mno-sym32 @gol
606 -G@var{num} -membedded-data -mno-embedded-data @gol
607 -muninit-const-in-rodata -mno-uninit-const-in-rodata @gol
608 -msplit-addresses -mno-split-addresses @gol
609 -mexplicit-relocs -mno-explicit-relocs @gol
610 -mcheck-zero-division -mno-check-zero-division @gol
611 -mdivide-traps -mdivide-breaks @gol
612 -mmemcpy -mno-memcpy -mlong-calls -mno-long-calls @gol
613 -mmad -mno-mad -mfused-madd -mno-fused-madd -nocpp @gol
614 -mfix-r4000 -mno-fix-r4000 -mfix-r4400 -mno-fix-r4400 @gol
615 -mfix-vr4120 -mno-fix-vr4120 -mfix-vr4130 @gol
616 -mfix-sb1 -mno-fix-sb1 @gol
617 -mflush-func=@var{func} -mno-flush-func @gol
618 -mbranch-likely -mno-branch-likely @gol
619 -mfp-exceptions -mno-fp-exceptions @gol
620 -mvr4130-align -mno-vr4130-align}
623 @gccoptlist{-mlibfuncs -mno-libfuncs -mepsilon -mno-epsilon -mabi=gnu @gol
624 -mabi=mmixware -mzero-extend -mknuthdiv -mtoplevel-symbols @gol
625 -melf -mbranch-predict -mno-branch-predict -mbase-addresses @gol
626 -mno-base-addresses -msingle-exit -mno-single-exit}
628 @emph{MN10300 Options}
629 @gccoptlist{-mmult-bug -mno-mult-bug @gol
630 -mam33 -mno-am33 @gol
631 -mam33-2 -mno-am33-2 @gol
632 -mreturn-pointer-on-d0 @gol
636 @gccoptlist{-mno-crt0 -mbacc -msim @gol
637 -march=@var{cpu-type} }
639 @emph{PDP-11 Options}
640 @gccoptlist{-mfpu -msoft-float -mac0 -mno-ac0 -m40 -m45 -m10 @gol
641 -mbcopy -mbcopy-builtin -mint32 -mno-int16 @gol
642 -mint16 -mno-int32 -mfloat32 -mno-float64 @gol
643 -mfloat64 -mno-float32 -mabshi -mno-abshi @gol
644 -mbranch-expensive -mbranch-cheap @gol
645 -msplit -mno-split -munix-asm -mdec-asm}
647 @emph{PowerPC Options}
648 See RS/6000 and PowerPC Options.
650 @emph{RS/6000 and PowerPC Options}
651 @gccoptlist{-mcpu=@var{cpu-type} @gol
652 -mtune=@var{cpu-type} @gol
653 -mpower -mno-power -mpower2 -mno-power2 @gol
654 -mpowerpc -mpowerpc64 -mno-powerpc @gol
655 -maltivec -mno-altivec @gol
656 -mpowerpc-gpopt -mno-powerpc-gpopt @gol
657 -mpowerpc-gfxopt -mno-powerpc-gfxopt @gol
658 -mmfcrf -mno-mfcrf -mpopcntb -mno-popcntb -mfprnd -mno-fprnd @gol
659 -mnew-mnemonics -mold-mnemonics @gol
660 -mfull-toc -mminimal-toc -mno-fp-in-toc -mno-sum-in-toc @gol
661 -m64 -m32 -mxl-compat -mno-xl-compat -mpe @gol
662 -malign-power -malign-natural @gol
663 -msoft-float -mhard-float -mmultiple -mno-multiple @gol
664 -mstring -mno-string -mupdate -mno-update @gol
665 -mfused-madd -mno-fused-madd -mbit-align -mno-bit-align @gol
666 -mstrict-align -mno-strict-align -mrelocatable @gol
667 -mno-relocatable -mrelocatable-lib -mno-relocatable-lib @gol
668 -mtoc -mno-toc -mlittle -mlittle-endian -mbig -mbig-endian @gol
669 -mdynamic-no-pic -maltivec -mswdiv @gol
670 -mprioritize-restricted-insns=@var{priority} @gol
671 -msched-costly-dep=@var{dependence_type} @gol
672 -minsert-sched-nops=@var{scheme} @gol
673 -mcall-sysv -mcall-netbsd @gol
674 -maix-struct-return -msvr4-struct-return @gol
675 -mabi=@var{abi-type} -msecure-plt -mbss-plt @gol
676 -misel -mno-isel @gol
677 -misel=yes -misel=no @gol
679 -mspe=yes -mspe=no @gol
680 -mvrsave -mno-vrsave @gol
681 -mmulhw -mno-mulhw @gol
682 -mdlmzb -mno-dlmzb @gol
683 -mfloat-gprs=yes -mfloat-gprs=no -mfloat-gprs=single -mfloat-gprs=double @gol
684 -mprototype -mno-prototype @gol
685 -msim -mmvme -mads -myellowknife -memb -msdata @gol
686 -msdata=@var{opt} -mvxworks -mwindiss -G @var{num} -pthread}
688 @emph{S/390 and zSeries Options}
689 @gccoptlist{-mtune=@var{cpu-type} -march=@var{cpu-type} @gol
690 -mhard-float -msoft-float -mlong-double-64 -mlong-double-128 @gol
691 -mbackchain -mno-backchain -mpacked-stack -mno-packed-stack @gol
692 -msmall-exec -mno-small-exec -mmvcle -mno-mvcle @gol
693 -m64 -m31 -mdebug -mno-debug -mesa -mzarch @gol
694 -mtpf-trace -mno-tpf-trace -mfused-madd -mno-fused-madd @gol
695 -mwarn-framesize -mwarn-dynamicstack -mstack-size -mstack-guard}
698 @gccoptlist{-mel -mel @gol
703 @gccoptlist{-m1 -m2 -m2e -m3 -m3e @gol
704 -m4-nofpu -m4-single-only -m4-single -m4 @gol
705 -m4a-nofpu -m4a-single-only -m4a-single -m4a -m4al @gol
706 -m5-64media -m5-64media-nofpu @gol
707 -m5-32media -m5-32media-nofpu @gol
708 -m5-compact -m5-compact-nofpu @gol
709 -mb -ml -mdalign -mrelax @gol
710 -mbigtable -mfmovd -mhitachi -mrenesas -mno-renesas -mnomacsave @gol
711 -mieee -misize -mpadstruct -mspace @gol
712 -mprefergot -musermode -multcost=@var{number} -mdiv=@var{strategy} @gol
713 -mdivsi3_libfunc=@var{name} @gol
714 -madjust-unroll -mindexed-addressing -mgettrcost=@var{number} -mpt-fixed @gol
718 @gccoptlist{-mcpu=@var{cpu-type} @gol
719 -mtune=@var{cpu-type} @gol
720 -mcmodel=@var{code-model} @gol
721 -m32 -m64 -mapp-regs -mno-app-regs @gol
722 -mfaster-structs -mno-faster-structs @gol
723 -mfpu -mno-fpu -mhard-float -msoft-float @gol
724 -mhard-quad-float -msoft-quad-float @gol
725 -mimpure-text -mno-impure-text -mlittle-endian @gol
726 -mstack-bias -mno-stack-bias @gol
727 -munaligned-doubles -mno-unaligned-doubles @gol
728 -mv8plus -mno-v8plus -mvis -mno-vis
729 -threads -pthreads -pthread}
731 @emph{System V Options}
732 @gccoptlist{-Qy -Qn -YP,@var{paths} -Ym,@var{dir}}
734 @emph{TMS320C3x/C4x Options}
735 @gccoptlist{-mcpu=@var{cpu} -mbig -msmall -mregparm -mmemparm @gol
736 -mfast-fix -mmpyi -mbk -mti -mdp-isr-reload @gol
737 -mrpts=@var{count} -mrptb -mdb -mloop-unsigned @gol
738 -mparallel-insns -mparallel-mpy -mpreserve-float}
741 @gccoptlist{-mlong-calls -mno-long-calls -mep -mno-ep @gol
742 -mprolog-function -mno-prolog-function -mspace @gol
743 -mtda=@var{n} -msda=@var{n} -mzda=@var{n} @gol
744 -mapp-regs -mno-app-regs @gol
745 -mdisable-callt -mno-disable-callt @gol
751 @gccoptlist{-mg -mgnu -munix}
753 @emph{x86-64 Options}
754 See i386 and x86-64 Options.
756 @emph{Xstormy16 Options}
759 @emph{Xtensa Options}
760 @gccoptlist{-mconst16 -mno-const16 @gol
761 -mfused-madd -mno-fused-madd @gol
762 -mtext-section-literals -mno-text-section-literals @gol
763 -mtarget-align -mno-target-align @gol
764 -mlongcalls -mno-longcalls}
766 @emph{zSeries Options}
767 See S/390 and zSeries Options.
769 @item Code Generation Options
770 @xref{Code Gen Options,,Options for Code Generation Conventions}.
771 @gccoptlist{-fcall-saved-@var{reg} -fcall-used-@var{reg} @gol
772 -ffixed-@var{reg} -fexceptions @gol
773 -fnon-call-exceptions -funwind-tables @gol
774 -fasynchronous-unwind-tables @gol
775 -finhibit-size-directive -finstrument-functions @gol
776 -fno-common -fno-ident @gol
777 -fpcc-struct-return -fpic -fPIC -fpie -fPIE @gol
778 -fno-jump-tables @gol
779 -freg-struct-return -fshort-enums @gol
780 -fshort-double -fshort-wchar @gol
781 -fverbose-asm -fpack-struct[=@var{n}] -fstack-check @gol
782 -fstack-limit-register=@var{reg} -fstack-limit-symbol=@var{sym} @gol
783 -fargument-alias -fargument-noalias @gol
784 -fargument-noalias-global -fargument-noalias-anything
785 -fleading-underscore -ftls-model=@var{model} @gol
786 -ftrapv -fwrapv -fbounds-check @gol
791 * Overall Options:: Controlling the kind of output:
792 an executable, object files, assembler files,
793 or preprocessed source.
794 * C Dialect Options:: Controlling the variant of C language compiled.
795 * C++ Dialect Options:: Variations on C++.
796 * Objective-C and Objective-C++ Dialect Options:: Variations on Objective-C
798 * Language Independent Options:: Controlling how diagnostics should be
800 * Warning Options:: How picky should the compiler be?
801 * Debugging Options:: Symbol tables, measurements, and debugging dumps.
802 * Optimize Options:: How much optimization?
803 * Preprocessor Options:: Controlling header files and macro definitions.
804 Also, getting dependency information for Make.
805 * Assembler Options:: Passing options to the assembler.
806 * Link Options:: Specifying libraries and so on.
807 * Directory Options:: Where to find header files and libraries.
808 Where to find the compiler executable files.
809 * Spec Files:: How to pass switches to sub-processes.
810 * Target Options:: Running a cross-compiler, or an old version of GCC.
813 @node Overall Options
814 @section Options Controlling the Kind of Output
816 Compilation can involve up to four stages: preprocessing, compilation
817 proper, assembly and linking, always in that order. GCC is capable of
818 preprocessing and compiling several files either into several
819 assembler input files, or into one assembler input file; then each
820 assembler input file produces an object file, and linking combines all
821 the object files (those newly compiled, and those specified as input)
822 into an executable file.
824 @cindex file name suffix
825 For any given input file, the file name suffix determines what kind of
830 C source code which must be preprocessed.
833 C source code which should not be preprocessed.
836 C++ source code which should not be preprocessed.
839 Objective-C source code. Note that you must link with the @file{libobjc}
840 library to make an Objective-C program work.
843 Objective-C source code which should not be preprocessed.
847 Objective-C++ source code. Note that you must link with the @file{libobjc}
848 library to make an Objective-C++ program work. Note that @samp{.M} refers
849 to a literal capital M@.
852 Objective-C++ source code which should not be preprocessed.
855 C, C++, Objective-C or Objective-C++ header file to be turned into a
860 @itemx @var{file}.cxx
861 @itemx @var{file}.cpp
862 @itemx @var{file}.CPP
863 @itemx @var{file}.c++
865 C++ source code which must be preprocessed. Note that in @samp{.cxx},
866 the last two letters must both be literally @samp{x}. Likewise,
867 @samp{.C} refers to a literal capital C@.
871 Objective-C++ source code which must be preprocessed.
874 Objective-C++ source code which should not be preprocessed.
878 C++ header file to be turned into a precompiled header.
881 @itemx @var{file}.for
882 @itemx @var{file}.FOR
883 Fixed form Fortran source code which should not be preprocessed.
886 @itemx @var{file}.fpp
887 @itemx @var{file}.FPP
888 Fixed form Fortran source code which must be preprocessed (with the traditional
892 @itemx @var{file}.f95
893 Free form Fortran source code which should not be preprocessed.
896 @itemx @var{file}.F95
897 Free form Fortran source code which must be preprocessed (with the
898 traditional preprocessor).
900 @c FIXME: Descriptions of Java file types.
907 Ada source code file which contains a library unit declaration (a
908 declaration of a package, subprogram, or generic, or a generic
909 instantiation), or a library unit renaming declaration (a package,
910 generic, or subprogram renaming declaration). Such files are also
913 @itemx @var{file}.adb
914 Ada source code file containing a library unit body (a subprogram or
915 package body). Such files are also called @dfn{bodies}.
917 @c GCC also knows about some suffixes for languages not yet included:
928 Assembler code which must be preprocessed.
931 An object file to be fed straight into linking.
932 Any file name with no recognized suffix is treated this way.
936 You can specify the input language explicitly with the @option{-x} option:
939 @item -x @var{language}
940 Specify explicitly the @var{language} for the following input files
941 (rather than letting the compiler choose a default based on the file
942 name suffix). This option applies to all following input files until
943 the next @option{-x} option. Possible values for @var{language} are:
945 c c-header c-cpp-output
946 c++ c++-header c++-cpp-output
947 objective-c objective-c-header objective-c-cpp-output
948 objective-c++ objective-c++-header objective-c++-cpp-output
949 assembler assembler-with-cpp
957 Turn off any specification of a language, so that subsequent files are
958 handled according to their file name suffixes (as they are if @option{-x}
959 has not been used at all).
961 @item -pass-exit-codes
962 @opindex pass-exit-codes
963 Normally the @command{gcc} program will exit with the code of 1 if any
964 phase of the compiler returns a non-success return code. If you specify
965 @option{-pass-exit-codes}, the @command{gcc} program will instead return with
966 numerically highest error produced by any phase that returned an error
967 indication. The C, C++, and Fortran frontends return 4, if an internal
968 compiler error is encountered.
971 If you only want some of the stages of compilation, you can use
972 @option{-x} (or filename suffixes) to tell @command{gcc} where to start, and
973 one of the options @option{-c}, @option{-S}, or @option{-E} to say where
974 @command{gcc} is to stop. Note that some combinations (for example,
975 @samp{-x cpp-output -E}) instruct @command{gcc} to do nothing at all.
980 Compile or assemble the source files, but do not link. The linking
981 stage simply is not done. The ultimate output is in the form of an
982 object file for each source file.
984 By default, the object file name for a source file is made by replacing
985 the suffix @samp{.c}, @samp{.i}, @samp{.s}, etc., with @samp{.o}.
987 Unrecognized input files, not requiring compilation or assembly, are
992 Stop after the stage of compilation proper; do not assemble. The output
993 is in the form of an assembler code file for each non-assembler input
996 By default, the assembler file name for a source file is made by
997 replacing the suffix @samp{.c}, @samp{.i}, etc., with @samp{.s}.
999 Input files that don't require compilation are ignored.
1003 Stop after the preprocessing stage; do not run the compiler proper. The
1004 output is in the form of preprocessed source code, which is sent to the
1007 Input files which don't require preprocessing are ignored.
1009 @cindex output file option
1012 Place output in file @var{file}. This applies regardless to whatever
1013 sort of output is being produced, whether it be an executable file,
1014 an object file, an assembler file or preprocessed C code.
1016 If @option{-o} is not specified, the default is to put an executable
1017 file in @file{a.out}, the object file for
1018 @file{@var{source}.@var{suffix}} in @file{@var{source}.o}, its
1019 assembler file in @file{@var{source}.s}, a precompiled header file in
1020 @file{@var{source}.@var{suffix}.gch}, and all preprocessed C source on
1025 Print (on standard error output) the commands executed to run the stages
1026 of compilation. Also print the version number of the compiler driver
1027 program and of the preprocessor and the compiler proper.
1031 Like @option{-v} except the commands are not executed and all command
1032 arguments are quoted. This is useful for shell scripts to capture the
1033 driver-generated command lines.
1037 Use pipes rather than temporary files for communication between the
1038 various stages of compilation. This fails to work on some systems where
1039 the assembler is unable to read from a pipe; but the GNU assembler has
1044 If you are compiling multiple source files, this option tells the driver
1045 to pass all the source files to the compiler at once (for those
1046 languages for which the compiler can handle this). This will allow
1047 intermodule analysis (IMA) to be performed by the compiler. Currently the only
1048 language for which this is supported is C@. If you pass source files for
1049 multiple languages to the driver, using this option, the driver will invoke
1050 the compiler(s) that support IMA once each, passing each compiler all the
1051 source files appropriate for it. For those languages that do not support
1052 IMA this option will be ignored, and the compiler will be invoked once for
1053 each source file in that language. If you use this option in conjunction
1054 with @option{-save-temps}, the compiler will generate multiple
1056 (one for each source file), but only one (combined) @file{.o} or
1061 Print (on the standard output) a description of the command line options
1062 understood by @command{gcc}. If the @option{-v} option is also specified
1063 then @option{--help} will also be passed on to the various processes
1064 invoked by @command{gcc}, so that they can display the command line options
1065 they accept. If the @option{-Wextra} option is also specified then command
1066 line options which have no documentation associated with them will also
1070 @opindex target-help
1071 Print (on the standard output) a description of target specific command
1072 line options for each tool.
1076 Display the version number and copyrights of the invoked GCC@.
1078 @include @value{srcdir}/../libiberty/at-file.texi
1082 @section Compiling C++ Programs
1084 @cindex suffixes for C++ source
1085 @cindex C++ source file suffixes
1086 C++ source files conventionally use one of the suffixes @samp{.C},
1087 @samp{.cc}, @samp{.cpp}, @samp{.CPP}, @samp{.c++}, @samp{.cp}, or
1088 @samp{.cxx}; C++ header files often use @samp{.hh} or @samp{.H}; and
1089 preprocessed C++ files use the suffix @samp{.ii}. GCC recognizes
1090 files with these names and compiles them as C++ programs even if you
1091 call the compiler the same way as for compiling C programs (usually
1092 with the name @command{gcc}).
1096 However, the use of @command{gcc} does not add the C++ library.
1097 @command{g++} is a program that calls GCC and treats @samp{.c},
1098 @samp{.h} and @samp{.i} files as C++ source files instead of C source
1099 files unless @option{-x} is used, and automatically specifies linking
1100 against the C++ library. This program is also useful when
1101 precompiling a C header file with a @samp{.h} extension for use in C++
1102 compilations. On many systems, @command{g++} is also installed with
1103 the name @command{c++}.
1105 @cindex invoking @command{g++}
1106 When you compile C++ programs, you may specify many of the same
1107 command-line options that you use for compiling programs in any
1108 language; or command-line options meaningful for C and related
1109 languages; or options that are meaningful only for C++ programs.
1110 @xref{C Dialect Options,,Options Controlling C Dialect}, for
1111 explanations of options for languages related to C@.
1112 @xref{C++ Dialect Options,,Options Controlling C++ Dialect}, for
1113 explanations of options that are meaningful only for C++ programs.
1115 @node C Dialect Options
1116 @section Options Controlling C Dialect
1117 @cindex dialect options
1118 @cindex language dialect options
1119 @cindex options, dialect
1121 The following options control the dialect of C (or languages derived
1122 from C, such as C++, Objective-C and Objective-C++) that the compiler
1126 @cindex ANSI support
1130 In C mode, support all ISO C90 programs. In C++ mode,
1131 remove GNU extensions that conflict with ISO C++.
1133 This turns off certain features of GCC that are incompatible with ISO
1134 C90 (when compiling C code), or of standard C++ (when compiling C++ code),
1135 such as the @code{asm} and @code{typeof} keywords, and
1136 predefined macros such as @code{unix} and @code{vax} that identify the
1137 type of system you are using. It also enables the undesirable and
1138 rarely used ISO trigraph feature. For the C compiler,
1139 it disables recognition of C++ style @samp{//} comments as well as
1140 the @code{inline} keyword.
1142 The alternate keywords @code{__asm__}, @code{__extension__},
1143 @code{__inline__} and @code{__typeof__} continue to work despite
1144 @option{-ansi}. You would not want to use them in an ISO C program, of
1145 course, but it is useful to put them in header files that might be included
1146 in compilations done with @option{-ansi}. Alternate predefined macros
1147 such as @code{__unix__} and @code{__vax__} are also available, with or
1148 without @option{-ansi}.
1150 The @option{-ansi} option does not cause non-ISO programs to be
1151 rejected gratuitously. For that, @option{-pedantic} is required in
1152 addition to @option{-ansi}. @xref{Warning Options}.
1154 The macro @code{__STRICT_ANSI__} is predefined when the @option{-ansi}
1155 option is used. Some header files may notice this macro and refrain
1156 from declaring certain functions or defining certain macros that the
1157 ISO standard doesn't call for; this is to avoid interfering with any
1158 programs that might use these names for other things.
1160 Functions which would normally be built in but do not have semantics
1161 defined by ISO C (such as @code{alloca} and @code{ffs}) are not built-in
1162 functions with @option{-ansi} is used. @xref{Other Builtins,,Other
1163 built-in functions provided by GCC}, for details of the functions
1168 Determine the language standard. This option is currently only
1169 supported when compiling C or C++. A value for this option must be
1170 provided; possible values are
1175 ISO C90 (same as @option{-ansi}).
1177 @item iso9899:199409
1178 ISO C90 as modified in amendment 1.
1184 ISO C99. Note that this standard is not yet fully supported; see
1185 @w{@uref{http://gcc.gnu.org/c99status.html}} for more information. The
1186 names @samp{c9x} and @samp{iso9899:199x} are deprecated.
1189 Default, ISO C90 plus GNU extensions (including some C99 features).
1193 ISO C99 plus GNU extensions. When ISO C99 is fully implemented in GCC,
1194 this will become the default. The name @samp{gnu9x} is deprecated.
1197 The 1998 ISO C++ standard plus amendments.
1200 The same as @option{-std=c++98} plus GNU extensions. This is the
1201 default for C++ code.
1204 Even when this option is not specified, you can still use some of the
1205 features of newer standards in so far as they do not conflict with
1206 previous C standards. For example, you may use @code{__restrict__} even
1207 when @option{-std=c99} is not specified.
1209 The @option{-std} options specifying some version of ISO C have the same
1210 effects as @option{-ansi}, except that features that were not in ISO C90
1211 but are in the specified version (for example, @samp{//} comments and
1212 the @code{inline} keyword in ISO C99) are not disabled.
1214 @xref{Standards,,Language Standards Supported by GCC}, for details of
1215 these standard versions.
1217 @item -aux-info @var{filename}
1219 Output to the given filename prototyped declarations for all functions
1220 declared and/or defined in a translation unit, including those in header
1221 files. This option is silently ignored in any language other than C@.
1223 Besides declarations, the file indicates, in comments, the origin of
1224 each declaration (source file and line), whether the declaration was
1225 implicit, prototyped or unprototyped (@samp{I}, @samp{N} for new or
1226 @samp{O} for old, respectively, in the first character after the line
1227 number and the colon), and whether it came from a declaration or a
1228 definition (@samp{C} or @samp{F}, respectively, in the following
1229 character). In the case of function definitions, a K&R-style list of
1230 arguments followed by their declarations is also provided, inside
1231 comments, after the declaration.
1235 Do not recognize @code{asm}, @code{inline} or @code{typeof} as a
1236 keyword, so that code can use these words as identifiers. You can use
1237 the keywords @code{__asm__}, @code{__inline__} and @code{__typeof__}
1238 instead. @option{-ansi} implies @option{-fno-asm}.
1240 In C++, this switch only affects the @code{typeof} keyword, since
1241 @code{asm} and @code{inline} are standard keywords. You may want to
1242 use the @option{-fno-gnu-keywords} flag instead, which has the same
1243 effect. In C99 mode (@option{-std=c99} or @option{-std=gnu99}), this
1244 switch only affects the @code{asm} and @code{typeof} keywords, since
1245 @code{inline} is a standard keyword in ISO C99.
1248 @itemx -fno-builtin-@var{function}
1249 @opindex fno-builtin
1250 @cindex built-in functions
1251 Don't recognize built-in functions that do not begin with
1252 @samp{__builtin_} as prefix. @xref{Other Builtins,,Other built-in
1253 functions provided by GCC}, for details of the functions affected,
1254 including those which are not built-in functions when @option{-ansi} or
1255 @option{-std} options for strict ISO C conformance are used because they
1256 do not have an ISO standard meaning.
1258 GCC normally generates special code to handle certain built-in functions
1259 more efficiently; for instance, calls to @code{alloca} may become single
1260 instructions that adjust the stack directly, and calls to @code{memcpy}
1261 may become inline copy loops. The resulting code is often both smaller
1262 and faster, but since the function calls no longer appear as such, you
1263 cannot set a breakpoint on those calls, nor can you change the behavior
1264 of the functions by linking with a different library. In addition,
1265 when a function is recognized as a built-in function, GCC may use
1266 information about that function to warn about problems with calls to
1267 that function, or to generate more efficient code, even if the
1268 resulting code still contains calls to that function. For example,
1269 warnings are given with @option{-Wformat} for bad calls to
1270 @code{printf}, when @code{printf} is built in, and @code{strlen} is
1271 known not to modify global memory.
1273 With the @option{-fno-builtin-@var{function}} option
1274 only the built-in function @var{function} is
1275 disabled. @var{function} must not begin with @samp{__builtin_}. If a
1276 function is named this is not built-in in this version of GCC, this
1277 option is ignored. There is no corresponding
1278 @option{-fbuiltin-@var{function}} option; if you wish to enable
1279 built-in functions selectively when using @option{-fno-builtin} or
1280 @option{-ffreestanding}, you may define macros such as:
1283 #define abs(n) __builtin_abs ((n))
1284 #define strcpy(d, s) __builtin_strcpy ((d), (s))
1289 @cindex hosted environment
1291 Assert that compilation takes place in a hosted environment. This implies
1292 @option{-fbuiltin}. A hosted environment is one in which the
1293 entire standard library is available, and in which @code{main} has a return
1294 type of @code{int}. Examples are nearly everything except a kernel.
1295 This is equivalent to @option{-fno-freestanding}.
1297 @item -ffreestanding
1298 @opindex ffreestanding
1299 @cindex hosted environment
1301 Assert that compilation takes place in a freestanding environment. This
1302 implies @option{-fno-builtin}. A freestanding environment
1303 is one in which the standard library may not exist, and program startup may
1304 not necessarily be at @code{main}. The most obvious example is an OS kernel.
1305 This is equivalent to @option{-fno-hosted}.
1307 @xref{Standards,,Language Standards Supported by GCC}, for details of
1308 freestanding and hosted environments.
1312 @cindex openmp parallel
1313 Enable handling of OpenMP directives @code{#pragma omp} in C/C++ and
1314 @code{!$omp} in Fortran. When @option{-fopenmp} is specified, the
1315 compiler generates parallel code according to the OpenMP Application
1316 Program Interface v2.5 @w{@uref{http://www.openmp.org/}}.
1318 @item -fms-extensions
1319 @opindex fms-extensions
1320 Accept some non-standard constructs used in Microsoft header files.
1322 Some cases of unnamed fields in structures and unions are only
1323 accepted with this option. @xref{Unnamed Fields,,Unnamed struct/union
1324 fields within structs/unions}, for details.
1328 Support ISO C trigraphs. The @option{-ansi} option (and @option{-std}
1329 options for strict ISO C conformance) implies @option{-trigraphs}.
1331 @item -no-integrated-cpp
1332 @opindex no-integrated-cpp
1333 Performs a compilation in two passes: preprocessing and compiling. This
1334 option allows a user supplied "cc1", "cc1plus", or "cc1obj" via the
1335 @option{-B} option. The user supplied compilation step can then add in
1336 an additional preprocessing step after normal preprocessing but before
1337 compiling. The default is to use the integrated cpp (internal cpp)
1339 The semantics of this option will change if "cc1", "cc1plus", and
1340 "cc1obj" are merged.
1342 @cindex traditional C language
1343 @cindex C language, traditional
1345 @itemx -traditional-cpp
1346 @opindex traditional-cpp
1347 @opindex traditional
1348 Formerly, these options caused GCC to attempt to emulate a pre-standard
1349 C compiler. They are now only supported with the @option{-E} switch.
1350 The preprocessor continues to support a pre-standard mode. See the GNU
1351 CPP manual for details.
1353 @item -fcond-mismatch
1354 @opindex fcond-mismatch
1355 Allow conditional expressions with mismatched types in the second and
1356 third arguments. The value of such an expression is void. This option
1357 is not supported for C++.
1359 @item -funsigned-char
1360 @opindex funsigned-char
1361 Let the type @code{char} be unsigned, like @code{unsigned char}.
1363 Each kind of machine has a default for what @code{char} should
1364 be. It is either like @code{unsigned char} by default or like
1365 @code{signed char} by default.
1367 Ideally, a portable program should always use @code{signed char} or
1368 @code{unsigned char} when it depends on the signedness of an object.
1369 But many programs have been written to use plain @code{char} and
1370 expect it to be signed, or expect it to be unsigned, depending on the
1371 machines they were written for. This option, and its inverse, let you
1372 make such a program work with the opposite default.
1374 The type @code{char} is always a distinct type from each of
1375 @code{signed char} or @code{unsigned char}, even though its behavior
1376 is always just like one of those two.
1379 @opindex fsigned-char
1380 Let the type @code{char} be signed, like @code{signed char}.
1382 Note that this is equivalent to @option{-fno-unsigned-char}, which is
1383 the negative form of @option{-funsigned-char}. Likewise, the option
1384 @option{-fno-signed-char} is equivalent to @option{-funsigned-char}.
1386 @item -fsigned-bitfields
1387 @itemx -funsigned-bitfields
1388 @itemx -fno-signed-bitfields
1389 @itemx -fno-unsigned-bitfields
1390 @opindex fsigned-bitfields
1391 @opindex funsigned-bitfields
1392 @opindex fno-signed-bitfields
1393 @opindex fno-unsigned-bitfields
1394 These options control whether a bit-field is signed or unsigned, when the
1395 declaration does not use either @code{signed} or @code{unsigned}. By
1396 default, such a bit-field is signed, because this is consistent: the
1397 basic integer types such as @code{int} are signed types.
1400 @node C++ Dialect Options
1401 @section Options Controlling C++ Dialect
1403 @cindex compiler options, C++
1404 @cindex C++ options, command line
1405 @cindex options, C++
1406 This section describes the command-line options that are only meaningful
1407 for C++ programs; but you can also use most of the GNU compiler options
1408 regardless of what language your program is in. For example, you
1409 might compile a file @code{firstClass.C} like this:
1412 g++ -g -frepo -O -c firstClass.C
1416 In this example, only @option{-frepo} is an option meant
1417 only for C++ programs; you can use the other options with any
1418 language supported by GCC@.
1420 Here is a list of options that are @emph{only} for compiling C++ programs:
1424 @item -fabi-version=@var{n}
1425 @opindex fabi-version
1426 Use version @var{n} of the C++ ABI@. Version 2 is the version of the
1427 C++ ABI that first appeared in G++ 3.4. Version 1 is the version of
1428 the C++ ABI that first appeared in G++ 3.2. Version 0 will always be
1429 the version that conforms most closely to the C++ ABI specification.
1430 Therefore, the ABI obtained using version 0 will change as ABI bugs
1433 The default is version 2.
1435 @item -fno-access-control
1436 @opindex fno-access-control
1437 Turn off all access checking. This switch is mainly useful for working
1438 around bugs in the access control code.
1442 Check that the pointer returned by @code{operator new} is non-null
1443 before attempting to modify the storage allocated. This check is
1444 normally unnecessary because the C++ standard specifies that
1445 @code{operator new} will only return @code{0} if it is declared
1446 @samp{throw()}, in which case the compiler will always check the
1447 return value even without this option. In all other cases, when
1448 @code{operator new} has a non-empty exception specification, memory
1449 exhaustion is signalled by throwing @code{std::bad_alloc}. See also
1450 @samp{new (nothrow)}.
1452 @item -fconserve-space
1453 @opindex fconserve-space
1454 Put uninitialized or runtime-initialized global variables into the
1455 common segment, as C does. This saves space in the executable at the
1456 cost of not diagnosing duplicate definitions. If you compile with this
1457 flag and your program mysteriously crashes after @code{main()} has
1458 completed, you may have an object that is being destroyed twice because
1459 two definitions were merged.
1461 This option is no longer useful on most targets, now that support has
1462 been added for putting variables into BSS without making them common.
1464 @item -ffriend-injection
1465 @opindex ffriend-injection
1466 Inject friend functions into the enclosing namespace, so that they are
1467 visible outside the scope of the class in which they are declared.
1468 Friend functions were documented to work this way in the old Annotated
1469 C++ Reference Manual, and versions of G++ before 4.1 always worked
1470 that way. However, in ISO C++ a friend function which is not declared
1471 in an enclosing scope can only be found using argument dependent
1472 lookup. This option causes friends to be injected as they were in
1475 This option is for compatibility, and may be removed in a future
1478 @item -fno-elide-constructors
1479 @opindex fno-elide-constructors
1480 The C++ standard allows an implementation to omit creating a temporary
1481 which is only used to initialize another object of the same type.
1482 Specifying this option disables that optimization, and forces G++ to
1483 call the copy constructor in all cases.
1485 @item -fno-enforce-eh-specs
1486 @opindex fno-enforce-eh-specs
1487 Don't generate code to check for violation of exception specifications
1488 at runtime. This option violates the C++ standard, but may be useful
1489 for reducing code size in production builds, much like defining
1490 @samp{NDEBUG}. This does not give user code permission to throw
1491 exceptions in violation of the exception specifications; the compiler
1492 will still optimize based on the specifications, so throwing an
1493 unexpected exception will result in undefined behavior.
1496 @itemx -fno-for-scope
1498 @opindex fno-for-scope
1499 If @option{-ffor-scope} is specified, the scope of variables declared in
1500 a @i{for-init-statement} is limited to the @samp{for} loop itself,
1501 as specified by the C++ standard.
1502 If @option{-fno-for-scope} is specified, the scope of variables declared in
1503 a @i{for-init-statement} extends to the end of the enclosing scope,
1504 as was the case in old versions of G++, and other (traditional)
1505 implementations of C++.
1507 The default if neither flag is given to follow the standard,
1508 but to allow and give a warning for old-style code that would
1509 otherwise be invalid, or have different behavior.
1511 @item -fno-gnu-keywords
1512 @opindex fno-gnu-keywords
1513 Do not recognize @code{typeof} as a keyword, so that code can use this
1514 word as an identifier. You can use the keyword @code{__typeof__} instead.
1515 @option{-ansi} implies @option{-fno-gnu-keywords}.
1517 @item -fno-implicit-templates
1518 @opindex fno-implicit-templates
1519 Never emit code for non-inline templates which are instantiated
1520 implicitly (i.e.@: by use); only emit code for explicit instantiations.
1521 @xref{Template Instantiation}, for more information.
1523 @item -fno-implicit-inline-templates
1524 @opindex fno-implicit-inline-templates
1525 Don't emit code for implicit instantiations of inline templates, either.
1526 The default is to handle inlines differently so that compiles with and
1527 without optimization will need the same set of explicit instantiations.
1529 @item -fno-implement-inlines
1530 @opindex fno-implement-inlines
1531 To save space, do not emit out-of-line copies of inline functions
1532 controlled by @samp{#pragma implementation}. This will cause linker
1533 errors if these functions are not inlined everywhere they are called.
1535 @item -fms-extensions
1536 @opindex fms-extensions
1537 Disable pedantic warnings about constructs used in MFC, such as implicit
1538 int and getting a pointer to member function via non-standard syntax.
1540 @item -fno-nonansi-builtins
1541 @opindex fno-nonansi-builtins
1542 Disable built-in declarations of functions that are not mandated by
1543 ANSI/ISO C@. These include @code{ffs}, @code{alloca}, @code{_exit},
1544 @code{index}, @code{bzero}, @code{conjf}, and other related functions.
1546 @item -fno-operator-names
1547 @opindex fno-operator-names
1548 Do not treat the operator name keywords @code{and}, @code{bitand},
1549 @code{bitor}, @code{compl}, @code{not}, @code{or} and @code{xor} as
1550 synonyms as keywords.
1552 @item -fno-optional-diags
1553 @opindex fno-optional-diags
1554 Disable diagnostics that the standard says a compiler does not need to
1555 issue. Currently, the only such diagnostic issued by G++ is the one for
1556 a name having multiple meanings within a class.
1559 @opindex fpermissive
1560 Downgrade some diagnostics about nonconformant code from errors to
1561 warnings. Thus, using @option{-fpermissive} will allow some
1562 nonconforming code to compile.
1566 Enable automatic template instantiation at link time. This option also
1567 implies @option{-fno-implicit-templates}. @xref{Template
1568 Instantiation}, for more information.
1572 Disable generation of information about every class with virtual
1573 functions for use by the C++ runtime type identification features
1574 (@samp{dynamic_cast} and @samp{typeid}). If you don't use those parts
1575 of the language, you can save some space by using this flag. Note that
1576 exception handling uses the same information, but it will generate it as
1577 needed. The @samp{dynamic_cast} operator can still be used for casts that
1578 do not require runtime type information, i.e. casts to @code{void *} or to
1579 unambiguous base classes.
1583 Emit statistics about front-end processing at the end of the compilation.
1584 This information is generally only useful to the G++ development team.
1586 @item -ftemplate-depth-@var{n}
1587 @opindex ftemplate-depth
1588 Set the maximum instantiation depth for template classes to @var{n}.
1589 A limit on the template instantiation depth is needed to detect
1590 endless recursions during template class instantiation. ANSI/ISO C++
1591 conforming programs must not rely on a maximum depth greater than 17.
1593 @item -fno-threadsafe-statics
1594 @opindex fno-threadsafe-statics
1595 Do not emit the extra code to use the routines specified in the C++
1596 ABI for thread-safe initialization of local statics. You can use this
1597 option to reduce code size slightly in code that doesn't need to be
1600 @item -fuse-cxa-atexit
1601 @opindex fuse-cxa-atexit
1602 Register destructors for objects with static storage duration with the
1603 @code{__cxa_atexit} function rather than the @code{atexit} function.
1604 This option is required for fully standards-compliant handling of static
1605 destructors, but will only work if your C library supports
1606 @code{__cxa_atexit}.
1608 @item -fno-use-cxa-get-exception-ptr
1609 @opindex fno-use-cxa-get-exception-ptr
1610 Don't use the @code{__cxa_get_exception_ptr} runtime routine. This
1611 will cause @code{std::uncaught_exception} to be incorrect, but is necessary
1612 if the runtime routine is not available.
1614 @item -fvisibility-inlines-hidden
1615 @opindex fvisibility-inlines-hidden
1616 This switch declares that the user does not attempt to compare
1617 pointers to inline methods where the addresses of the two functions
1618 were taken in different shared objects.
1620 The effect of this is that GCC may, effectively, mark inline methods with
1621 @code{__attribute__ ((visibility ("hidden")))} so that they do not
1622 appear in the export table of a DSO and do not require a PLT indirection
1623 when used within the DSO@. Enabling this option can have a dramatic effect
1624 on load and link times of a DSO as it massively reduces the size of the
1625 dynamic export table when the library makes heavy use of templates.
1627 The behaviour of this switch is not quite the same as marking the
1628 methods as hidden directly, because it does not affect static variables
1629 local to the function or cause the compiler to deduce that
1630 the function is defined in only one shared object.
1632 You may mark a method as having a visibility explicitly to negate the
1633 effect of the switch for that method. For example, if you do want to
1634 compare pointers to a particular inline method, you might mark it as
1635 having default visibility. Marking the enclosing class with explicit
1636 visibility will have no effect.
1638 Explicitly instantiated inline methods are unaffected by this option
1639 as their linkage might otherwise cross a shared library boundary.
1640 @xref{Template Instantiation}.
1644 Do not use weak symbol support, even if it is provided by the linker.
1645 By default, G++ will use weak symbols if they are available. This
1646 option exists only for testing, and should not be used by end-users;
1647 it will result in inferior code and has no benefits. This option may
1648 be removed in a future release of G++.
1652 Do not search for header files in the standard directories specific to
1653 C++, but do still search the other standard directories. (This option
1654 is used when building the C++ library.)
1657 In addition, these optimization, warning, and code generation options
1658 have meanings only for C++ programs:
1661 @item -fno-default-inline
1662 @opindex fno-default-inline
1663 Do not assume @samp{inline} for functions defined inside a class scope.
1664 @xref{Optimize Options,,Options That Control Optimization}. Note that these
1665 functions will have linkage like inline functions; they just won't be
1668 @item -Wabi @r{(C++ only)}
1670 Warn when G++ generates code that is probably not compatible with the
1671 vendor-neutral C++ ABI@. Although an effort has been made to warn about
1672 all such cases, there are probably some cases that are not warned about,
1673 even though G++ is generating incompatible code. There may also be
1674 cases where warnings are emitted even though the code that is generated
1677 You should rewrite your code to avoid these warnings if you are
1678 concerned about the fact that code generated by G++ may not be binary
1679 compatible with code generated by other compilers.
1681 The known incompatibilities at this point include:
1686 Incorrect handling of tail-padding for bit-fields. G++ may attempt to
1687 pack data into the same byte as a base class. For example:
1690 struct A @{ virtual void f(); int f1 : 1; @};
1691 struct B : public A @{ int f2 : 1; @};
1695 In this case, G++ will place @code{B::f2} into the same byte
1696 as@code{A::f1}; other compilers will not. You can avoid this problem
1697 by explicitly padding @code{A} so that its size is a multiple of the
1698 byte size on your platform; that will cause G++ and other compilers to
1699 layout @code{B} identically.
1702 Incorrect handling of tail-padding for virtual bases. G++ does not use
1703 tail padding when laying out virtual bases. For example:
1706 struct A @{ virtual void f(); char c1; @};
1707 struct B @{ B(); char c2; @};
1708 struct C : public A, public virtual B @{@};
1712 In this case, G++ will not place @code{B} into the tail-padding for
1713 @code{A}; other compilers will. You can avoid this problem by
1714 explicitly padding @code{A} so that its size is a multiple of its
1715 alignment (ignoring virtual base classes); that will cause G++ and other
1716 compilers to layout @code{C} identically.
1719 Incorrect handling of bit-fields with declared widths greater than that
1720 of their underlying types, when the bit-fields appear in a union. For
1724 union U @{ int i : 4096; @};
1728 Assuming that an @code{int} does not have 4096 bits, G++ will make the
1729 union too small by the number of bits in an @code{int}.
1732 Empty classes can be placed at incorrect offsets. For example:
1742 struct C : public B, public A @{@};
1746 G++ will place the @code{A} base class of @code{C} at a nonzero offset;
1747 it should be placed at offset zero. G++ mistakenly believes that the
1748 @code{A} data member of @code{B} is already at offset zero.
1751 Names of template functions whose types involve @code{typename} or
1752 template template parameters can be mangled incorrectly.
1755 template <typename Q>
1756 void f(typename Q::X) @{@}
1758 template <template <typename> class Q>
1759 void f(typename Q<int>::X) @{@}
1763 Instantiations of these templates may be mangled incorrectly.
1767 @item -Wctor-dtor-privacy @r{(C++ only)}
1768 @opindex Wctor-dtor-privacy
1769 Warn when a class seems unusable because all the constructors or
1770 destructors in that class are private, and it has neither friends nor
1771 public static member functions.
1773 @item -Wnon-virtual-dtor @r{(C++ only)}
1774 @opindex Wnon-virtual-dtor
1775 Warn when a class appears to be polymorphic, thereby requiring a virtual
1776 destructor, yet it declares a non-virtual one. This warning is also
1777 enabled if -Weffc++ is specified.
1779 @item -Wreorder @r{(C++ only)}
1781 @cindex reordering, warning
1782 @cindex warning for reordering of member initializers
1783 Warn when the order of member initializers given in the code does not
1784 match the order in which they must be executed. For instance:
1790 A(): j (0), i (1) @{ @}
1794 The compiler will rearrange the member initializers for @samp{i}
1795 and @samp{j} to match the declaration order of the members, emitting
1796 a warning to that effect. This warning is enabled by @option{-Wall}.
1799 The following @option{-W@dots{}} options are not affected by @option{-Wall}.
1802 @item -Weffc++ @r{(C++ only)}
1804 Warn about violations of the following style guidelines from Scott Meyers'
1805 @cite{Effective C++} book:
1809 Item 11: Define a copy constructor and an assignment operator for classes
1810 with dynamically allocated memory.
1813 Item 12: Prefer initialization to assignment in constructors.
1816 Item 14: Make destructors virtual in base classes.
1819 Item 15: Have @code{operator=} return a reference to @code{*this}.
1822 Item 23: Don't try to return a reference when you must return an object.
1826 Also warn about violations of the following style guidelines from
1827 Scott Meyers' @cite{More Effective C++} book:
1831 Item 6: Distinguish between prefix and postfix forms of increment and
1832 decrement operators.
1835 Item 7: Never overload @code{&&}, @code{||}, or @code{,}.
1839 When selecting this option, be aware that the standard library
1840 headers do not obey all of these guidelines; use @samp{grep -v}
1841 to filter out those warnings.
1843 @item -Wno-deprecated @r{(C++ only)}
1844 @opindex Wno-deprecated
1845 Do not warn about usage of deprecated features. @xref{Deprecated Features}.
1847 @item -Wstrict-null-sentinel @r{(C++ only)}
1848 @opindex Wstrict-null-sentinel
1849 Warn also about the use of an uncasted @code{NULL} as sentinel. When
1850 compiling only with GCC this is a valid sentinel, as @code{NULL} is defined
1851 to @code{__null}. Although it is a null pointer constant not a null pointer,
1852 it is guaranteed to of the same size as a pointer. But this use is
1853 not portable across different compilers.
1855 @item -Wno-non-template-friend @r{(C++ only)}
1856 @opindex Wno-non-template-friend
1857 Disable warnings when non-templatized friend functions are declared
1858 within a template. Since the advent of explicit template specification
1859 support in G++, if the name of the friend is an unqualified-id (i.e.,
1860 @samp{friend foo(int)}), the C++ language specification demands that the
1861 friend declare or define an ordinary, nontemplate function. (Section
1862 14.5.3). Before G++ implemented explicit specification, unqualified-ids
1863 could be interpreted as a particular specialization of a templatized
1864 function. Because this non-conforming behavior is no longer the default
1865 behavior for G++, @option{-Wnon-template-friend} allows the compiler to
1866 check existing code for potential trouble spots and is on by default.
1867 This new compiler behavior can be turned off with
1868 @option{-Wno-non-template-friend} which keeps the conformant compiler code
1869 but disables the helpful warning.
1871 @item -Wold-style-cast @r{(C++ only)}
1872 @opindex Wold-style-cast
1873 Warn if an old-style (C-style) cast to a non-void type is used within
1874 a C++ program. The new-style casts (@samp{dynamic_cast},
1875 @samp{static_cast}, @samp{reinterpret_cast}, and @samp{const_cast}) are
1876 less vulnerable to unintended effects and much easier to search for.
1878 @item -Woverloaded-virtual @r{(C++ only)}
1879 @opindex Woverloaded-virtual
1880 @cindex overloaded virtual fn, warning
1881 @cindex warning for overloaded virtual fn
1882 Warn when a function declaration hides virtual functions from a
1883 base class. For example, in:
1890 struct B: public A @{
1895 the @code{A} class version of @code{f} is hidden in @code{B}, and code
1903 will fail to compile.
1905 @item -Wno-pmf-conversions @r{(C++ only)}
1906 @opindex Wno-pmf-conversions
1907 Disable the diagnostic for converting a bound pointer to member function
1910 @item -Wsign-promo @r{(C++ only)}
1911 @opindex Wsign-promo
1912 Warn when overload resolution chooses a promotion from unsigned or
1913 enumerated type to a signed type, over a conversion to an unsigned type of
1914 the same size. Previous versions of G++ would try to preserve
1915 unsignedness, but the standard mandates the current behavior.
1920 A& operator = (int);
1930 In this example, G++ will synthesize a default @samp{A& operator =
1931 (const A&);}, while cfront will use the user-defined @samp{operator =}.
1934 @node Objective-C and Objective-C++ Dialect Options
1935 @section Options Controlling Objective-C and Objective-C++ Dialects
1937 @cindex compiler options, Objective-C and Objective-C++
1938 @cindex Objective-C and Objective-C++ options, command line
1939 @cindex options, Objective-C and Objective-C++
1940 (NOTE: This manual does not describe the Objective-C and Objective-C++
1941 languages themselves. See @xref{Standards,,Language Standards
1942 Supported by GCC}, for references.)
1944 This section describes the command-line options that are only meaningful
1945 for Objective-C and Objective-C++ programs, but you can also use most of
1946 the language-independent GNU compiler options.
1947 For example, you might compile a file @code{some_class.m} like this:
1950 gcc -g -fgnu-runtime -O -c some_class.m
1954 In this example, @option{-fgnu-runtime} is an option meant only for
1955 Objective-C and Objective-C++ programs; you can use the other options with
1956 any language supported by GCC@.
1958 Note that since Objective-C is an extension of the C language, Objective-C
1959 compilations may also use options specific to the C front-end (e.g.,
1960 @option{-Wtraditional}). Similarly, Objective-C++ compilations may use
1961 C++-specific options (e.g., @option{-Wabi}).
1963 Here is a list of options that are @emph{only} for compiling Objective-C
1964 and Objective-C++ programs:
1967 @item -fconstant-string-class=@var{class-name}
1968 @opindex fconstant-string-class
1969 Use @var{class-name} as the name of the class to instantiate for each
1970 literal string specified with the syntax @code{@@"@dots{}"}. The default
1971 class name is @code{NXConstantString} if the GNU runtime is being used, and
1972 @code{NSConstantString} if the NeXT runtime is being used (see below). The
1973 @option{-fconstant-cfstrings} option, if also present, will override the
1974 @option{-fconstant-string-class} setting and cause @code{@@"@dots{}"} literals
1975 to be laid out as constant CoreFoundation strings.
1978 @opindex fgnu-runtime
1979 Generate object code compatible with the standard GNU Objective-C
1980 runtime. This is the default for most types of systems.
1982 @item -fnext-runtime
1983 @opindex fnext-runtime
1984 Generate output compatible with the NeXT runtime. This is the default
1985 for NeXT-based systems, including Darwin and Mac OS X@. The macro
1986 @code{__NEXT_RUNTIME__} is predefined if (and only if) this option is
1989 @item -fno-nil-receivers
1990 @opindex fno-nil-receivers
1991 Assume that all Objective-C message dispatches (e.g.,
1992 @code{[receiver message:arg]}) in this translation unit ensure that the receiver
1993 is not @code{nil}. This allows for more efficient entry points in the runtime
1994 to be used. Currently, this option is only available in conjunction with
1995 the NeXT runtime on Mac OS X 10.3 and later.
1997 @item -fobjc-call-cxx-cdtors
1998 @opindex fobjc-call-cxx-cdtors
1999 For each Objective-C class, check if any of its instance variables is a
2000 C++ object with a non-trivial default constructor. If so, synthesize a
2001 special @code{- (id) .cxx_construct} instance method that will run
2002 non-trivial default constructors on any such instance variables, in order,
2003 and then return @code{self}. Similarly, check if any instance variable
2004 is a C++ object with a non-trivial destructor, and if so, synthesize a
2005 special @code{- (void) .cxx_destruct} method that will run
2006 all such default destructors, in reverse order.
2008 The @code{- (id) .cxx_construct} and/or @code{- (void) .cxx_destruct} methods
2009 thusly generated will only operate on instance variables declared in the
2010 current Objective-C class, and not those inherited from superclasses. It
2011 is the responsibility of the Objective-C runtime to invoke all such methods
2012 in an object's inheritance hierarchy. The @code{- (id) .cxx_construct} methods
2013 will be invoked by the runtime immediately after a new object
2014 instance is allocated; the @code{- (void) .cxx_destruct} methods will
2015 be invoked immediately before the runtime deallocates an object instance.
2017 As of this writing, only the NeXT runtime on Mac OS X 10.4 and later has
2018 support for invoking the @code{- (id) .cxx_construct} and
2019 @code{- (void) .cxx_destruct} methods.
2021 @item -fobjc-direct-dispatch
2022 @opindex fobjc-direct-dispatch
2023 Allow fast jumps to the message dispatcher. On Darwin this is
2024 accomplished via the comm page.
2026 @item -fobjc-exceptions
2027 @opindex fobjc-exceptions
2028 Enable syntactic support for structured exception handling in Objective-C,
2029 similar to what is offered by C++ and Java. This option is
2030 unavailable in conjunction with the NeXT runtime on Mac OS X 10.2 and
2039 @@catch (AnObjCClass *exc) @{
2046 @@catch (AnotherClass *exc) @{
2049 @@catch (id allOthers) @{
2059 The @code{@@throw} statement may appear anywhere in an Objective-C or
2060 Objective-C++ program; when used inside of a @code{@@catch} block, the
2061 @code{@@throw} may appear without an argument (as shown above), in which case
2062 the object caught by the @code{@@catch} will be rethrown.
2064 Note that only (pointers to) Objective-C objects may be thrown and
2065 caught using this scheme. When an object is thrown, it will be caught
2066 by the nearest @code{@@catch} clause capable of handling objects of that type,
2067 analogously to how @code{catch} blocks work in C++ and Java. A
2068 @code{@@catch(id @dots{})} clause (as shown above) may also be provided to catch
2069 any and all Objective-C exceptions not caught by previous @code{@@catch}
2072 The @code{@@finally} clause, if present, will be executed upon exit from the
2073 immediately preceding @code{@@try @dots{} @@catch} section. This will happen
2074 regardless of whether any exceptions are thrown, caught or rethrown
2075 inside the @code{@@try @dots{} @@catch} section, analogously to the behavior
2076 of the @code{finally} clause in Java.
2078 There are several caveats to using the new exception mechanism:
2082 Although currently designed to be binary compatible with @code{NS_HANDLER}-style
2083 idioms provided by the @code{NSException} class, the new
2084 exceptions can only be used on Mac OS X 10.3 (Panther) and later
2085 systems, due to additional functionality needed in the (NeXT) Objective-C
2089 As mentioned above, the new exceptions do not support handling
2090 types other than Objective-C objects. Furthermore, when used from
2091 Objective-C++, the Objective-C exception model does not interoperate with C++
2092 exceptions at this time. This means you cannot @code{@@throw} an exception
2093 from Objective-C and @code{catch} it in C++, or vice versa
2094 (i.e., @code{throw @dots{} @@catch}).
2097 The @option{-fobjc-exceptions} switch also enables the use of synchronization
2098 blocks for thread-safe execution:
2101 @@synchronized (ObjCClass *guard) @{
2106 Upon entering the @code{@@synchronized} block, a thread of execution shall
2107 first check whether a lock has been placed on the corresponding @code{guard}
2108 object by another thread. If it has, the current thread shall wait until
2109 the other thread relinquishes its lock. Once @code{guard} becomes available,
2110 the current thread will place its own lock on it, execute the code contained in
2111 the @code{@@synchronized} block, and finally relinquish the lock (thereby
2112 making @code{guard} available to other threads).
2114 Unlike Java, Objective-C does not allow for entire methods to be marked
2115 @code{@@synchronized}. Note that throwing exceptions out of
2116 @code{@@synchronized} blocks is allowed, and will cause the guarding object
2117 to be unlocked properly.
2121 Enable garbage collection (GC) in Objective-C and Objective-C++ programs.
2123 @item -freplace-objc-classes
2124 @opindex freplace-objc-classes
2125 Emit a special marker instructing @command{ld(1)} not to statically link in
2126 the resulting object file, and allow @command{dyld(1)} to load it in at
2127 run time instead. This is used in conjunction with the Fix-and-Continue
2128 debugging mode, where the object file in question may be recompiled and
2129 dynamically reloaded in the course of program execution, without the need
2130 to restart the program itself. Currently, Fix-and-Continue functionality
2131 is only available in conjunction with the NeXT runtime on Mac OS X 10.3
2136 When compiling for the NeXT runtime, the compiler ordinarily replaces calls
2137 to @code{objc_getClass("@dots{}")} (when the name of the class is known at
2138 compile time) with static class references that get initialized at load time,
2139 which improves run-time performance. Specifying the @option{-fzero-link} flag
2140 suppresses this behavior and causes calls to @code{objc_getClass("@dots{}")}
2141 to be retained. This is useful in Zero-Link debugging mode, since it allows
2142 for individual class implementations to be modified during program execution.
2146 Dump interface declarations for all classes seen in the source file to a
2147 file named @file{@var{sourcename}.decl}.
2149 @item -Wassign-intercept
2150 @opindex Wassign-intercept
2151 Warn whenever an Objective-C assignment is being intercepted by the
2155 @opindex Wno-protocol
2156 If a class is declared to implement a protocol, a warning is issued for
2157 every method in the protocol that is not implemented by the class. The
2158 default behavior is to issue a warning for every method not explicitly
2159 implemented in the class, even if a method implementation is inherited
2160 from the superclass. If you use the @option{-Wno-protocol} option, then
2161 methods inherited from the superclass are considered to be implemented,
2162 and no warning is issued for them.
2166 Warn if multiple methods of different types for the same selector are
2167 found during compilation. The check is performed on the list of methods
2168 in the final stage of compilation. Additionally, a check is performed
2169 for each selector appearing in a @code{@@selector(@dots{})}
2170 expression, and a corresponding method for that selector has been found
2171 during compilation. Because these checks scan the method table only at
2172 the end of compilation, these warnings are not produced if the final
2173 stage of compilation is not reached, for example because an error is
2174 found during compilation, or because the @option{-fsyntax-only} option is
2177 @item -Wstrict-selector-match
2178 @opindex Wstrict-selector-match
2179 Warn if multiple methods with differing argument and/or return types are
2180 found for a given selector when attempting to send a message using this
2181 selector to a receiver of type @code{id} or @code{Class}. When this flag
2182 is off (which is the default behavior), the compiler will omit such warnings
2183 if any differences found are confined to types which share the same size
2186 @item -Wundeclared-selector
2187 @opindex Wundeclared-selector
2188 Warn if a @code{@@selector(@dots{})} expression referring to an
2189 undeclared selector is found. A selector is considered undeclared if no
2190 method with that name has been declared before the
2191 @code{@@selector(@dots{})} expression, either explicitly in an
2192 @code{@@interface} or @code{@@protocol} declaration, or implicitly in
2193 an @code{@@implementation} section. This option always performs its
2194 checks as soon as a @code{@@selector(@dots{})} expression is found,
2195 while @option{-Wselector} only performs its checks in the final stage of
2196 compilation. This also enforces the coding style convention
2197 that methods and selectors must be declared before being used.
2199 @item -print-objc-runtime-info
2200 @opindex print-objc-runtime-info
2201 Generate C header describing the largest structure that is passed by
2206 @node Language Independent Options
2207 @section Options to Control Diagnostic Messages Formatting
2208 @cindex options to control diagnostics formatting
2209 @cindex diagnostic messages
2210 @cindex message formatting
2212 Traditionally, diagnostic messages have been formatted irrespective of
2213 the output device's aspect (e.g.@: its width, @dots{}). The options described
2214 below can be used to control the diagnostic messages formatting
2215 algorithm, e.g.@: how many characters per line, how often source location
2216 information should be reported. Right now, only the C++ front end can
2217 honor these options. However it is expected, in the near future, that
2218 the remaining front ends would be able to digest them correctly.
2221 @item -fmessage-length=@var{n}
2222 @opindex fmessage-length
2223 Try to format error messages so that they fit on lines of about @var{n}
2224 characters. The default is 72 characters for @command{g++} and 0 for the rest of
2225 the front ends supported by GCC@. If @var{n} is zero, then no
2226 line-wrapping will be done; each error message will appear on a single
2229 @opindex fdiagnostics-show-location
2230 @item -fdiagnostics-show-location=once
2231 Only meaningful in line-wrapping mode. Instructs the diagnostic messages
2232 reporter to emit @emph{once} source location information; that is, in
2233 case the message is too long to fit on a single physical line and has to
2234 be wrapped, the source location won't be emitted (as prefix) again,
2235 over and over, in subsequent continuation lines. This is the default
2238 @item -fdiagnostics-show-location=every-line
2239 Only meaningful in line-wrapping mode. Instructs the diagnostic
2240 messages reporter to emit the same source location information (as
2241 prefix) for physical lines that result from the process of breaking
2242 a message which is too long to fit on a single line.
2244 @item -fdiagnostics-show-option
2245 @opindex fdiagnostics-show-option
2246 This option instructs the diagnostic machinery to add text to each
2247 diagnostic emitted, which indicates which command line option directly
2248 controls that diagnostic, when such an option is known to the
2249 diagnostic machinery.
2253 @node Warning Options
2254 @section Options to Request or Suppress Warnings
2255 @cindex options to control warnings
2256 @cindex warning messages
2257 @cindex messages, warning
2258 @cindex suppressing warnings
2260 Warnings are diagnostic messages that report constructions which
2261 are not inherently erroneous but which are risky or suggest there
2262 may have been an error.
2264 You can request many specific warnings with options beginning @samp{-W},
2265 for example @option{-Wimplicit} to request warnings on implicit
2266 declarations. Each of these specific warning options also has a
2267 negative form beginning @samp{-Wno-} to turn off warnings;
2268 for example, @option{-Wno-implicit}. This manual lists only one of the
2269 two forms, whichever is not the default.
2271 The following options control the amount and kinds of warnings produced
2272 by GCC; for further, language-specific options also refer to
2273 @ref{C++ Dialect Options} and @ref{Objective-C and Objective-C++ Dialect
2277 @cindex syntax checking
2279 @opindex fsyntax-only
2280 Check the code for syntax errors, but don't do anything beyond that.
2284 Issue all the warnings demanded by strict ISO C and ISO C++;
2285 reject all programs that use forbidden extensions, and some other
2286 programs that do not follow ISO C and ISO C++. For ISO C, follows the
2287 version of the ISO C standard specified by any @option{-std} option used.
2289 Valid ISO C and ISO C++ programs should compile properly with or without
2290 this option (though a rare few will require @option{-ansi} or a
2291 @option{-std} option specifying the required version of ISO C)@. However,
2292 without this option, certain GNU extensions and traditional C and C++
2293 features are supported as well. With this option, they are rejected.
2295 @option{-pedantic} does not cause warning messages for use of the
2296 alternate keywords whose names begin and end with @samp{__}. Pedantic
2297 warnings are also disabled in the expression that follows
2298 @code{__extension__}. However, only system header files should use
2299 these escape routes; application programs should avoid them.
2300 @xref{Alternate Keywords}.
2302 Some users try to use @option{-pedantic} to check programs for strict ISO
2303 C conformance. They soon find that it does not do quite what they want:
2304 it finds some non-ISO practices, but not all---only those for which
2305 ISO C @emph{requires} a diagnostic, and some others for which
2306 diagnostics have been added.
2308 A feature to report any failure to conform to ISO C might be useful in
2309 some instances, but would require considerable additional work and would
2310 be quite different from @option{-pedantic}. We don't have plans to
2311 support such a feature in the near future.
2313 Where the standard specified with @option{-std} represents a GNU
2314 extended dialect of C, such as @samp{gnu89} or @samp{gnu99}, there is a
2315 corresponding @dfn{base standard}, the version of ISO C on which the GNU
2316 extended dialect is based. Warnings from @option{-pedantic} are given
2317 where they are required by the base standard. (It would not make sense
2318 for such warnings to be given only for features not in the specified GNU
2319 C dialect, since by definition the GNU dialects of C include all
2320 features the compiler supports with the given option, and there would be
2321 nothing to warn about.)
2323 @item -pedantic-errors
2324 @opindex pedantic-errors
2325 Like @option{-pedantic}, except that errors are produced rather than
2330 Inhibit all warning messages.
2334 Inhibit warning messages about the use of @samp{#import}.
2336 @item -Wchar-subscripts
2337 @opindex Wchar-subscripts
2338 Warn if an array subscript has type @code{char}. This is a common cause
2339 of error, as programmers often forget that this type is signed on some
2341 This warning is enabled by @option{-Wall}.
2345 Warn whenever a comment-start sequence @samp{/*} appears in a @samp{/*}
2346 comment, or whenever a Backslash-Newline appears in a @samp{//} comment.
2347 This warning is enabled by @option{-Wall}.
2349 @item -Wfatal-errors
2350 @opindex Wfatal-errors
2351 This option causes the compiler to abort compilation on the first error
2352 occurred rather than trying to keep going and printing further error
2357 @opindex ffreestanding
2358 @opindex fno-builtin
2359 Check calls to @code{printf} and @code{scanf}, etc., to make sure that
2360 the arguments supplied have types appropriate to the format string
2361 specified, and that the conversions specified in the format string make
2362 sense. This includes standard functions, and others specified by format
2363 attributes (@pxref{Function Attributes}), in the @code{printf},
2364 @code{scanf}, @code{strftime} and @code{strfmon} (an X/Open extension,
2365 not in the C standard) families (or other target-specific families).
2366 Which functions are checked without format attributes having been
2367 specified depends on the standard version selected, and such checks of
2368 functions without the attribute specified are disabled by
2369 @option{-ffreestanding} or @option{-fno-builtin}.
2371 The formats are checked against the format features supported by GNU
2372 libc version 2.2. These include all ISO C90 and C99 features, as well
2373 as features from the Single Unix Specification and some BSD and GNU
2374 extensions. Other library implementations may not support all these
2375 features; GCC does not support warning about features that go beyond a
2376 particular library's limitations. However, if @option{-pedantic} is used
2377 with @option{-Wformat}, warnings will be given about format features not
2378 in the selected standard version (but not for @code{strfmon} formats,
2379 since those are not in any version of the C standard). @xref{C Dialect
2380 Options,,Options Controlling C Dialect}.
2382 Since @option{-Wformat} also checks for null format arguments for
2383 several functions, @option{-Wformat} also implies @option{-Wnonnull}.
2385 @option{-Wformat} is included in @option{-Wall}. For more control over some
2386 aspects of format checking, the options @option{-Wformat-y2k},
2387 @option{-Wno-format-extra-args}, @option{-Wno-format-zero-length},
2388 @option{-Wformat-nonliteral}, @option{-Wformat-security}, and
2389 @option{-Wformat=2} are available, but are not included in @option{-Wall}.
2392 @opindex Wformat-y2k
2393 If @option{-Wformat} is specified, also warn about @code{strftime}
2394 formats which may yield only a two-digit year.
2396 @item -Wno-format-extra-args
2397 @opindex Wno-format-extra-args
2398 If @option{-Wformat} is specified, do not warn about excess arguments to a
2399 @code{printf} or @code{scanf} format function. The C standard specifies
2400 that such arguments are ignored.
2402 Where the unused arguments lie between used arguments that are
2403 specified with @samp{$} operand number specifications, normally
2404 warnings are still given, since the implementation could not know what
2405 type to pass to @code{va_arg} to skip the unused arguments. However,
2406 in the case of @code{scanf} formats, this option will suppress the
2407 warning if the unused arguments are all pointers, since the Single
2408 Unix Specification says that such unused arguments are allowed.
2410 @item -Wno-format-zero-length
2411 @opindex Wno-format-zero-length
2412 If @option{-Wformat} is specified, do not warn about zero-length formats.
2413 The C standard specifies that zero-length formats are allowed.
2415 @item -Wformat-nonliteral
2416 @opindex Wformat-nonliteral
2417 If @option{-Wformat} is specified, also warn if the format string is not a
2418 string literal and so cannot be checked, unless the format function
2419 takes its format arguments as a @code{va_list}.
2421 @item -Wformat-security
2422 @opindex Wformat-security
2423 If @option{-Wformat} is specified, also warn about uses of format
2424 functions that represent possible security problems. At present, this
2425 warns about calls to @code{printf} and @code{scanf} functions where the
2426 format string is not a string literal and there are no format arguments,
2427 as in @code{printf (foo);}. This may be a security hole if the format
2428 string came from untrusted input and contains @samp{%n}. (This is
2429 currently a subset of what @option{-Wformat-nonliteral} warns about, but
2430 in future warnings may be added to @option{-Wformat-security} that are not
2431 included in @option{-Wformat-nonliteral}.)
2435 Enable @option{-Wformat} plus format checks not included in
2436 @option{-Wformat}. Currently equivalent to @samp{-Wformat
2437 -Wformat-nonliteral -Wformat-security -Wformat-y2k}.
2441 Warn about passing a null pointer for arguments marked as
2442 requiring a non-null value by the @code{nonnull} function attribute.
2444 @option{-Wnonnull} is included in @option{-Wall} and @option{-Wformat}. It
2445 can be disabled with the @option{-Wno-nonnull} option.
2447 @item -Winit-self @r{(C, C++, Objective-C and Objective-C++ only)}
2449 Warn about uninitialized variables which are initialized with themselves.
2450 Note this option can only be used with the @option{-Wuninitialized} option,
2451 which in turn only works with @option{-O1} and above.
2453 For example, GCC will warn about @code{i} being uninitialized in the
2454 following snippet only when @option{-Winit-self} has been specified:
2465 @item -Wimplicit-int
2466 @opindex Wimplicit-int
2467 Warn when a declaration does not specify a type.
2468 This warning is enabled by @option{-Wall}.
2470 @item -Wimplicit-function-declaration
2471 @itemx -Werror-implicit-function-declaration
2472 @opindex Wimplicit-function-declaration
2473 @opindex Werror-implicit-function-declaration
2474 Give a warning (or error) whenever a function is used before being
2475 declared. The form @option{-Wno-error-implicit-function-declaration}
2477 This warning is enabled by @option{-Wall} (as a warning, not an error).
2481 Same as @option{-Wimplicit-int} and @option{-Wimplicit-function-declaration}.
2482 This warning is enabled by @option{-Wall}.
2486 Warn if the type of @samp{main} is suspicious. @samp{main} should be a
2487 function with external linkage, returning int, taking either zero
2488 arguments, two, or three arguments of appropriate types.
2489 This warning is enabled by @option{-Wall}.
2491 @item -Wmissing-braces
2492 @opindex Wmissing-braces
2493 Warn if an aggregate or union initializer is not fully bracketed. In
2494 the following example, the initializer for @samp{a} is not fully
2495 bracketed, but that for @samp{b} is fully bracketed.
2498 int a[2][2] = @{ 0, 1, 2, 3 @};
2499 int b[2][2] = @{ @{ 0, 1 @}, @{ 2, 3 @} @};
2502 This warning is enabled by @option{-Wall}.
2504 @item -Wmissing-include-dirs @r{(C, C++, Objective-C and Objective-C++ only)}
2505 @opindex Wmissing-include-dirs
2506 Warn if a user-supplied include directory does not exist.
2509 @opindex Wparentheses
2510 Warn if parentheses are omitted in certain contexts, such
2511 as when there is an assignment in a context where a truth value
2512 is expected, or when operators are nested whose precedence people
2513 often get confused about. Only the warning for an assignment used as
2514 a truth value is supported when compiling C++; the other warnings are
2515 only supported when compiling C@.
2517 Also warn if a comparison like @samp{x<=y<=z} appears; this is
2518 equivalent to @samp{(x<=y ? 1 : 0) <= z}, which is a different
2519 interpretation from that of ordinary mathematical notation.
2521 Also warn about constructions where there may be confusion to which
2522 @code{if} statement an @code{else} branch belongs. Here is an example of
2537 In C, every @code{else} branch belongs to the innermost possible @code{if}
2538 statement, which in this example is @code{if (b)}. This is often not
2539 what the programmer expected, as illustrated in the above example by
2540 indentation the programmer chose. When there is the potential for this
2541 confusion, GCC will issue a warning when this flag is specified.
2542 To eliminate the warning, add explicit braces around the innermost
2543 @code{if} statement so there is no way the @code{else} could belong to
2544 the enclosing @code{if}. The resulting code would look like this:
2560 This warning is enabled by @option{-Wall}.
2562 @item -Wsequence-point
2563 @opindex Wsequence-point
2564 Warn about code that may have undefined semantics because of violations
2565 of sequence point rules in the C and C++ standards.
2567 The C and C++ standards defines the order in which expressions in a C/C++
2568 program are evaluated in terms of @dfn{sequence points}, which represent
2569 a partial ordering between the execution of parts of the program: those
2570 executed before the sequence point, and those executed after it. These
2571 occur after the evaluation of a full expression (one which is not part
2572 of a larger expression), after the evaluation of the first operand of a
2573 @code{&&}, @code{||}, @code{? :} or @code{,} (comma) operator, before a
2574 function is called (but after the evaluation of its arguments and the
2575 expression denoting the called function), and in certain other places.
2576 Other than as expressed by the sequence point rules, the order of
2577 evaluation of subexpressions of an expression is not specified. All
2578 these rules describe only a partial order rather than a total order,
2579 since, for example, if two functions are called within one expression
2580 with no sequence point between them, the order in which the functions
2581 are called is not specified. However, the standards committee have
2582 ruled that function calls do not overlap.
2584 It is not specified when between sequence points modifications to the
2585 values of objects take effect. Programs whose behavior depends on this
2586 have undefined behavior; the C and C++ standards specify that ``Between
2587 the previous and next sequence point an object shall have its stored
2588 value modified at most once by the evaluation of an expression.
2589 Furthermore, the prior value shall be read only to determine the value
2590 to be stored.''. If a program breaks these rules, the results on any
2591 particular implementation are entirely unpredictable.
2593 Examples of code with undefined behavior are @code{a = a++;}, @code{a[n]
2594 = b[n++]} and @code{a[i++] = i;}. Some more complicated cases are not
2595 diagnosed by this option, and it may give an occasional false positive
2596 result, but in general it has been found fairly effective at detecting
2597 this sort of problem in programs.
2599 The standard is worded confusingly, therefore there is some debate
2600 over the precise meaning of the sequence point rules in subtle cases.
2601 Links to discussions of the problem, including proposed formal
2602 definitions, may be found on the GCC readings page, at
2603 @w{@uref{http://gcc.gnu.org/readings.html}}.
2605 This warning is enabled by @option{-Wall} for C and C++.
2608 @opindex Wreturn-type
2609 Warn whenever a function is defined with a return-type that defaults to
2610 @code{int}. Also warn about any @code{return} statement with no
2611 return-value in a function whose return-type is not @code{void}.
2613 For C, also warn if the return type of a function has a type qualifier
2614 such as @code{const}. Such a type qualifier has no effect, since the
2615 value returned by a function is not an lvalue. ISO C prohibits
2616 qualified @code{void} return types on function definitions, so such
2617 return types always receive a warning even without this option.
2619 For C++, a function without return type always produces a diagnostic
2620 message, even when @option{-Wno-return-type} is specified. The only
2621 exceptions are @samp{main} and functions defined in system headers.
2623 This warning is enabled by @option{-Wall}.
2627 Warn whenever a @code{switch} statement has an index of enumerated type
2628 and lacks a @code{case} for one or more of the named codes of that
2629 enumeration. (The presence of a @code{default} label prevents this
2630 warning.) @code{case} labels outside the enumeration range also
2631 provoke warnings when this option is used.
2632 This warning is enabled by @option{-Wall}.
2634 @item -Wswitch-default
2635 @opindex Wswitch-switch
2636 Warn whenever a @code{switch} statement does not have a @code{default}
2640 @opindex Wswitch-enum
2641 Warn whenever a @code{switch} statement has an index of enumerated type
2642 and lacks a @code{case} for one or more of the named codes of that
2643 enumeration. @code{case} labels outside the enumeration range also
2644 provoke warnings when this option is used.
2648 Warn if any trigraphs are encountered that might change the meaning of
2649 the program (trigraphs within comments are not warned about).
2650 This warning is enabled by @option{-Wall}.
2652 @item -Wunused-function
2653 @opindex Wunused-function
2654 Warn whenever a static function is declared but not defined or a
2655 non-inline static function is unused.
2656 This warning is enabled by @option{-Wall}.
2658 @item -Wunused-label
2659 @opindex Wunused-label
2660 Warn whenever a label is declared but not used.
2661 This warning is enabled by @option{-Wall}.
2663 To suppress this warning use the @samp{unused} attribute
2664 (@pxref{Variable Attributes}).
2666 @item -Wunused-parameter
2667 @opindex Wunused-parameter
2668 Warn whenever a function parameter is unused aside from its declaration.
2670 To suppress this warning use the @samp{unused} attribute
2671 (@pxref{Variable Attributes}).
2673 @item -Wunused-variable
2674 @opindex Wunused-variable
2675 Warn whenever a local variable or non-constant static variable is unused
2676 aside from its declaration.
2677 This warning is enabled by @option{-Wall}.
2679 To suppress this warning use the @samp{unused} attribute
2680 (@pxref{Variable Attributes}).
2682 @item -Wunused-value
2683 @opindex Wunused-value
2684 Warn whenever a statement computes a result that is explicitly not used.
2685 This warning is enabled by @option{-Wall}.
2687 To suppress this warning cast the expression to @samp{void}.
2691 All the above @option{-Wunused} options combined.
2693 In order to get a warning about an unused function parameter, you must
2694 either specify @samp{-Wextra -Wunused} (note that @samp{-Wall} implies
2695 @samp{-Wunused}), or separately specify @option{-Wunused-parameter}.
2697 @item -Wuninitialized
2698 @opindex Wuninitialized
2699 Warn if an automatic variable is used without first being initialized or
2700 if a variable may be clobbered by a @code{setjmp} call.
2702 These warnings are possible only in optimizing compilation,
2703 because they require data flow information that is computed only
2704 when optimizing. If you do not specify @option{-O}, you will not get
2705 these warnings. Instead, GCC will issue a warning about @option{-Wuninitialized}
2706 requiring @option{-O}.
2708 If you want to warn about code which uses the uninitialized value of the
2709 variable in its own initializer, use the @option{-Winit-self} option.
2711 These warnings occur for individual uninitialized or clobbered
2712 elements of structure, union or array variables as well as for
2713 variables which are uninitialized or clobbered as a whole. They do
2714 not occur for variables or elements declared @code{volatile}. Because
2715 these warnings depend on optimization, the exact variables or elements
2716 for which there are warnings will depend on the precise optimization
2717 options and version of GCC used.
2719 Note that there may be no warning about a variable that is used only
2720 to compute a value that itself is never used, because such
2721 computations may be deleted by data flow analysis before the warnings
2724 These warnings are made optional because GCC is not smart
2725 enough to see all the reasons why the code might be correct
2726 despite appearing to have an error. Here is one example of how
2747 If the value of @code{y} is always 1, 2 or 3, then @code{x} is
2748 always initialized, but GCC doesn't know this. Here is
2749 another common case:
2754 if (change_y) save_y = y, y = new_y;
2756 if (change_y) y = save_y;
2761 This has no bug because @code{save_y} is used only if it is set.
2763 @cindex @code{longjmp} warnings
2764 This option also warns when a non-volatile automatic variable might be
2765 changed by a call to @code{longjmp}. These warnings as well are possible
2766 only in optimizing compilation.
2768 The compiler sees only the calls to @code{setjmp}. It cannot know
2769 where @code{longjmp} will be called; in fact, a signal handler could
2770 call it at any point in the code. As a result, you may get a warning
2771 even when there is in fact no problem because @code{longjmp} cannot
2772 in fact be called at the place which would cause a problem.
2774 Some spurious warnings can be avoided if you declare all the functions
2775 you use that never return as @code{noreturn}. @xref{Function
2778 This warning is enabled by @option{-Wall}.
2780 @item -Wunknown-pragmas
2781 @opindex Wunknown-pragmas
2782 @cindex warning for unknown pragmas
2783 @cindex unknown pragmas, warning
2784 @cindex pragmas, warning of unknown
2785 Warn when a #pragma directive is encountered which is not understood by
2786 GCC@. If this command line option is used, warnings will even be issued
2787 for unknown pragmas in system header files. This is not the case if
2788 the warnings were only enabled by the @option{-Wall} command line option.
2791 @opindex Wno-pragmas
2793 Do not warn about misuses of pragmas, such as incorrect parameters,
2794 invalid syntax, or conflicts between pragmas. See also
2795 @samp{-Wunknown-pragmas}.
2797 @item -Wstrict-aliasing
2798 @opindex Wstrict-aliasing
2799 This option is only active when @option{-fstrict-aliasing} is active.
2800 It warns about code which might break the strict aliasing rules that the
2801 compiler is using for optimization. The warning does not catch all
2802 cases, but does attempt to catch the more common pitfalls. It is
2803 included in @option{-Wall}.
2805 @item -Wstrict-aliasing=2
2806 @opindex Wstrict-aliasing=2
2807 This option is only active when @option{-fstrict-aliasing} is active.
2808 It warns about code which might break the strict aliasing rules that the
2809 compiler is using for optimization. This warning catches more cases than
2810 @option{-Wstrict-aliasing}, but it will also give a warning for some ambiguous
2811 cases that are safe.
2815 All of the above @samp{-W} options combined. This enables all the
2816 warnings about constructions that some users consider questionable, and
2817 that are easy to avoid (or modify to prevent the warning), even in
2818 conjunction with macros. This also enables some language-specific
2819 warnings described in @ref{C++ Dialect Options} and
2820 @ref{Objective-C and Objective-C++ Dialect Options}.
2823 The following @option{-W@dots{}} options are not implied by @option{-Wall}.
2824 Some of them warn about constructions that users generally do not
2825 consider questionable, but which occasionally you might wish to check
2826 for; others warn about constructions that are necessary or hard to avoid
2827 in some cases, and there is no simple way to modify the code to suppress
2834 (This option used to be called @option{-W}. The older name is still
2835 supported, but the newer name is more descriptive.) Print extra warning
2836 messages for these events:
2840 A function can return either with or without a value. (Falling
2841 off the end of the function body is considered returning without
2842 a value.) For example, this function would evoke such a
2856 An expression-statement or the left-hand side of a comma expression
2857 contains no side effects.
2858 To suppress the warning, cast the unused expression to void.
2859 For example, an expression such as @samp{x[i,j]} will cause a warning,
2860 but @samp{x[(void)i,j]} will not.
2863 An unsigned value is compared against zero with @samp{<} or @samp{>=}.
2866 Storage-class specifiers like @code{static} are not the first things in
2867 a declaration. According to the C Standard, this usage is obsolescent.
2870 If @option{-Wall} or @option{-Wunused} is also specified, warn about unused
2874 A comparison between signed and unsigned values could produce an
2875 incorrect result when the signed value is converted to unsigned.
2876 (But don't warn if @option{-Wno-sign-compare} is also specified.)
2879 An aggregate has an initializer which does not initialize all members.
2880 This warning can be independently controlled by
2881 @option{-Wmissing-field-initializers}.
2884 An initialized field without side effects is overridden when using
2885 designated initializers (@pxref{Designated Inits, , Designated
2886 Initializers}). This warning can be independently controlled by
2887 @option{-Woverride-init}.
2890 A function parameter is declared without a type specifier in K&R-style
2898 An empty body occurs in an @samp{if} or @samp{else} statement.
2901 A pointer is compared against integer zero with @samp{<}, @samp{<=},
2902 @samp{>}, or @samp{>=}.
2905 A variable might be changed by @samp{longjmp} or @samp{vfork}.
2908 Any of several floating-point events that often indicate errors, such as
2909 overflow, underflow, loss of precision, etc.
2911 @item @r{(C++ only)}
2912 An enumerator and a non-enumerator both appear in a conditional expression.
2914 @item @r{(C++ only)}
2915 A non-static reference or non-static @samp{const} member appears in a
2916 class without constructors.
2918 @item @r{(C++ only)}
2919 Ambiguous virtual bases.
2921 @item @r{(C++ only)}
2922 Subscripting an array which has been declared @samp{register}.
2924 @item @r{(C++ only)}
2925 Taking the address of a variable which has been declared @samp{register}.
2927 @item @r{(C++ only)}
2928 A base class is not initialized in a derived class' copy constructor.
2931 @item -Wno-div-by-zero
2932 @opindex Wno-div-by-zero
2933 @opindex Wdiv-by-zero
2934 Do not warn about compile-time integer division by zero. Floating point
2935 division by zero is not warned about, as it can be a legitimate way of
2936 obtaining infinities and NaNs.
2938 @item -Wsystem-headers
2939 @opindex Wsystem-headers
2940 @cindex warnings from system headers
2941 @cindex system headers, warnings from
2942 Print warning messages for constructs found in system header files.
2943 Warnings from system headers are normally suppressed, on the assumption
2944 that they usually do not indicate real problems and would only make the
2945 compiler output harder to read. Using this command line option tells
2946 GCC to emit warnings from system headers as if they occurred in user
2947 code. However, note that using @option{-Wall} in conjunction with this
2948 option will @emph{not} warn about unknown pragmas in system
2949 headers---for that, @option{-Wunknown-pragmas} must also be used.
2952 @opindex Wfloat-equal
2953 Warn if floating point values are used in equality comparisons.
2955 The idea behind this is that sometimes it is convenient (for the
2956 programmer) to consider floating-point values as approximations to
2957 infinitely precise real numbers. If you are doing this, then you need
2958 to compute (by analyzing the code, or in some other way) the maximum or
2959 likely maximum error that the computation introduces, and allow for it
2960 when performing comparisons (and when producing output, but that's a
2961 different problem). In particular, instead of testing for equality, you
2962 would check to see whether the two values have ranges that overlap; and
2963 this is done with the relational operators, so equality comparisons are
2966 @item -Wtraditional @r{(C only)}
2967 @opindex Wtraditional
2968 Warn about certain constructs that behave differently in traditional and
2969 ISO C@. Also warn about ISO C constructs that have no traditional C
2970 equivalent, and/or problematic constructs which should be avoided.
2974 Macro parameters that appear within string literals in the macro body.
2975 In traditional C macro replacement takes place within string literals,
2976 but does not in ISO C@.
2979 In traditional C, some preprocessor directives did not exist.
2980 Traditional preprocessors would only consider a line to be a directive
2981 if the @samp{#} appeared in column 1 on the line. Therefore
2982 @option{-Wtraditional} warns about directives that traditional C
2983 understands but would ignore because the @samp{#} does not appear as the
2984 first character on the line. It also suggests you hide directives like
2985 @samp{#pragma} not understood by traditional C by indenting them. Some
2986 traditional implementations would not recognize @samp{#elif}, so it
2987 suggests avoiding it altogether.
2990 A function-like macro that appears without arguments.
2993 The unary plus operator.
2996 The @samp{U} integer constant suffix, or the @samp{F} or @samp{L} floating point
2997 constant suffixes. (Traditional C does support the @samp{L} suffix on integer
2998 constants.) Note, these suffixes appear in macros defined in the system
2999 headers of most modern systems, e.g.@: the @samp{_MIN}/@samp{_MAX} macros in @code{<limits.h>}.
3000 Use of these macros in user code might normally lead to spurious
3001 warnings, however GCC's integrated preprocessor has enough context to
3002 avoid warning in these cases.
3005 A function declared external in one block and then used after the end of
3009 A @code{switch} statement has an operand of type @code{long}.
3012 A non-@code{static} function declaration follows a @code{static} one.
3013 This construct is not accepted by some traditional C compilers.
3016 The ISO type of an integer constant has a different width or
3017 signedness from its traditional type. This warning is only issued if
3018 the base of the constant is ten. I.e.@: hexadecimal or octal values, which
3019 typically represent bit patterns, are not warned about.
3022 Usage of ISO string concatenation is detected.
3025 Initialization of automatic aggregates.
3028 Identifier conflicts with labels. Traditional C lacks a separate
3029 namespace for labels.
3032 Initialization of unions. If the initializer is zero, the warning is
3033 omitted. This is done under the assumption that the zero initializer in
3034 user code appears conditioned on e.g.@: @code{__STDC__} to avoid missing
3035 initializer warnings and relies on default initialization to zero in the
3039 Conversions by prototypes between fixed/floating point values and vice
3040 versa. The absence of these prototypes when compiling with traditional
3041 C would cause serious problems. This is a subset of the possible
3042 conversion warnings, for the full set use @option{-Wconversion}.
3045 Use of ISO C style function definitions. This warning intentionally is
3046 @emph{not} issued for prototype declarations or variadic functions
3047 because these ISO C features will appear in your code when using
3048 libiberty's traditional C compatibility macros, @code{PARAMS} and
3049 @code{VPARAMS}. This warning is also bypassed for nested functions
3050 because that feature is already a GCC extension and thus not relevant to
3051 traditional C compatibility.
3054 @item -Wdeclaration-after-statement @r{(C only)}
3055 @opindex Wdeclaration-after-statement
3056 Warn when a declaration is found after a statement in a block. This
3057 construct, known from C++, was introduced with ISO C99 and is by default
3058 allowed in GCC@. It is not supported by ISO C90 and was not supported by
3059 GCC versions before GCC 3.0. @xref{Mixed Declarations}.
3063 Warn if an undefined identifier is evaluated in an @samp{#if} directive.
3065 @item -Wno-endif-labels
3066 @opindex Wno-endif-labels
3067 @opindex Wendif-labels
3068 Do not warn whenever an @samp{#else} or an @samp{#endif} are followed by text.
3072 Warn whenever a local variable shadows another local variable, parameter or
3073 global variable or whenever a built-in function is shadowed.
3075 @item -Wlarger-than-@var{len}
3076 @opindex Wlarger-than
3077 Warn whenever an object of larger than @var{len} bytes is defined.
3079 @item -Wunsafe-loop-optimizations
3080 @opindex Wunsafe-loop-optimizations
3081 Warn if the loop cannot be optimized because the compiler could not
3082 assume anything on the bounds of the loop indices. With
3083 @option{-funsafe-loop-optimizations} warn if the compiler made
3086 @item -Wpointer-arith
3087 @opindex Wpointer-arith
3088 Warn about anything that depends on the ``size of'' a function type or
3089 of @code{void}. GNU C assigns these types a size of 1, for
3090 convenience in calculations with @code{void *} pointers and pointers
3093 @item -Wbad-function-cast @r{(C only)}
3094 @opindex Wbad-function-cast
3095 Warn whenever a function call is cast to a non-matching type.
3096 For example, warn if @code{int malloc()} is cast to @code{anything *}.
3099 Warn about ISO C constructs that are outside of the common subset of
3100 ISO C and ISO C++, e.g.@: request for implicit conversion from
3101 @code{void *} to a pointer to non-@code{void} type.
3105 Warn whenever a pointer is cast so as to remove a type qualifier from
3106 the target type. For example, warn if a @code{const char *} is cast
3107 to an ordinary @code{char *}.
3110 @opindex Wcast-align
3111 Warn whenever a pointer is cast such that the required alignment of the
3112 target is increased. For example, warn if a @code{char *} is cast to
3113 an @code{int *} on machines where integers can only be accessed at
3114 two- or four-byte boundaries.
3116 @item -Wwrite-strings
3117 @opindex Wwrite-strings
3118 When compiling C, give string constants the type @code{const
3119 char[@var{length}]} so that
3120 copying the address of one into a non-@code{const} @code{char *}
3121 pointer will get a warning; when compiling C++, warn about the
3122 deprecated conversion from string literals to @code{char *}. This
3123 warning, by default, is enabled for C++ programs.
3124 These warnings will help you find at
3125 compile time code that can try to write into a string constant, but
3126 only if you have been very careful about using @code{const} in
3127 declarations and prototypes. Otherwise, it will just be a nuisance;
3128 this is why we did not make @option{-Wall} request these warnings.
3131 @opindex Wconversion
3132 Warn if a prototype causes a type conversion that is different from what
3133 would happen to the same argument in the absence of a prototype. This
3134 includes conversions of fixed point to floating and vice versa, and
3135 conversions changing the width or signedness of a fixed point argument
3136 except when the same as the default promotion.
3138 Also, warn if a negative integer constant expression is implicitly
3139 converted to an unsigned type. For example, warn about the assignment
3140 @code{x = -1} if @code{x} is unsigned. But do not warn about explicit
3141 casts like @code{(unsigned) -1}.
3143 @item -Wsign-compare
3144 @opindex Wsign-compare
3145 @cindex warning for comparison of signed and unsigned values
3146 @cindex comparison of signed and unsigned values, warning
3147 @cindex signed and unsigned values, comparison warning
3148 Warn when a comparison between signed and unsigned values could produce
3149 an incorrect result when the signed value is converted to unsigned.
3150 This warning is also enabled by @option{-Wextra}; to get the other warnings
3151 of @option{-Wextra} without this warning, use @samp{-Wextra -Wno-sign-compare}.
3153 @item -Waggregate-return
3154 @opindex Waggregate-return
3155 Warn if any functions that return structures or unions are defined or
3156 called. (In languages where you can return an array, this also elicits
3160 @opindex Walways-true
3161 Warn about comparisons which are always true such as testing if
3162 unsigned values are greater than or equal to zero. This warning is
3163 enabled by @option{-Wall}.
3165 @item -Wno-attributes
3166 @opindex Wno-attributes
3167 @opindex Wattributes
3168 Do not warn if an unexpected @code{__attribute__} is used, such as
3169 unrecognized attributes, function attributes applied to variables,
3170 etc. This will not stop errors for incorrect use of supported
3173 @item -Wstrict-prototypes @r{(C only)}
3174 @opindex Wstrict-prototypes
3175 Warn if a function is declared or defined without specifying the
3176 argument types. (An old-style function definition is permitted without
3177 a warning if preceded by a declaration which specifies the argument
3180 @item -Wold-style-definition @r{(C only)}
3181 @opindex Wold-style-definition
3182 Warn if an old-style function definition is used. A warning is given
3183 even if there is a previous prototype.
3185 @item -Wmissing-prototypes @r{(C only)}
3186 @opindex Wmissing-prototypes
3187 Warn if a global function is defined without a previous prototype
3188 declaration. This warning is issued even if the definition itself
3189 provides a prototype. The aim is to detect global functions that fail
3190 to be declared in header files.
3192 @item -Wmissing-declarations @r{(C only)}
3193 @opindex Wmissing-declarations
3194 Warn if a global function is defined without a previous declaration.
3195 Do so even if the definition itself provides a prototype.
3196 Use this option to detect global functions that are not declared in
3199 @item -Wmissing-field-initializers
3200 @opindex Wmissing-field-initializers
3203 Warn if a structure's initializer has some fields missing. For
3204 example, the following code would cause such a warning, because
3205 @code{x.h} is implicitly zero:
3208 struct s @{ int f, g, h; @};
3209 struct s x = @{ 3, 4 @};
3212 This option does not warn about designated initializers, so the following
3213 modification would not trigger a warning:
3216 struct s @{ int f, g, h; @};
3217 struct s x = @{ .f = 3, .g = 4 @};
3220 This warning is included in @option{-Wextra}. To get other @option{-Wextra}
3221 warnings without this one, use @samp{-Wextra -Wno-missing-field-initializers}.
3223 @item -Wmissing-noreturn
3224 @opindex Wmissing-noreturn
3225 Warn about functions which might be candidates for attribute @code{noreturn}.
3226 Note these are only possible candidates, not absolute ones. Care should
3227 be taken to manually verify functions actually do not ever return before
3228 adding the @code{noreturn} attribute, otherwise subtle code generation
3229 bugs could be introduced. You will not get a warning for @code{main} in
3230 hosted C environments.
3232 @item -Wmissing-format-attribute
3233 @opindex Wmissing-format-attribute
3235 Warn about function pointers which might be candidates for @code{format}
3236 attributes. Note these are only possible candidates, not absolute ones.
3237 GCC will guess that function pointers with @code{format} attributes that
3238 are used in assignment, initialization, parameter passing or return
3239 statements should have a corresponding @code{format} attribute in the
3240 resulting type. I.e.@: the left-hand side of the assignment or
3241 initialization, the type of the parameter variable, or the return type
3242 of the containing function respectively should also have a @code{format}
3243 attribute to avoid the warning.
3245 GCC will also warn about function definitions which might be
3246 candidates for @code{format} attributes. Again, these are only
3247 possible candidates. GCC will guess that @code{format} attributes
3248 might be appropriate for any function that calls a function like
3249 @code{vprintf} or @code{vscanf}, but this might not always be the
3250 case, and some functions for which @code{format} attributes are
3251 appropriate may not be detected.
3253 @item -Wno-multichar
3254 @opindex Wno-multichar
3256 Do not warn if a multicharacter constant (@samp{'FOOF'}) is used.
3257 Usually they indicate a typo in the user's code, as they have
3258 implementation-defined values, and should not be used in portable code.
3260 @item -Wnormalized=<none|id|nfc|nfkc>
3261 @opindex Wnormalized
3264 @cindex character set, input normalization
3265 In ISO C and ISO C++, two identifiers are different if they are
3266 different sequences of characters. However, sometimes when characters
3267 outside the basic ASCII character set are used, you can have two
3268 different character sequences that look the same. To avoid confusion,
3269 the ISO 10646 standard sets out some @dfn{normalization rules} which
3270 when applied ensure that two sequences that look the same are turned into
3271 the same sequence. GCC can warn you if you are using identifiers which
3272 have not been normalized; this option controls that warning.
3274 There are four levels of warning that GCC supports. The default is
3275 @option{-Wnormalized=nfc}, which warns about any identifier which is
3276 not in the ISO 10646 ``C'' normalized form, @dfn{NFC}. NFC is the
3277 recommended form for most uses.
3279 Unfortunately, there are some characters which ISO C and ISO C++ allow
3280 in identifiers that when turned into NFC aren't allowable as
3281 identifiers. That is, there's no way to use these symbols in portable
3282 ISO C or C++ and have all your identifiers in NFC.
3283 @option{-Wnormalized=id} suppresses the warning for these characters.
3284 It is hoped that future versions of the standards involved will correct
3285 this, which is why this option is not the default.
3287 You can switch the warning off for all characters by writing
3288 @option{-Wnormalized=none}. You would only want to do this if you
3289 were using some other normalization scheme (like ``D''), because
3290 otherwise you can easily create bugs that are literally impossible to see.
3292 Some characters in ISO 10646 have distinct meanings but look identical
3293 in some fonts or display methodologies, especially once formatting has
3294 been applied. For instance @code{\u207F}, ``SUPERSCRIPT LATIN SMALL
3295 LETTER N'', will display just like a regular @code{n} which has been
3296 placed in a superscript. ISO 10646 defines the @dfn{NFKC}
3297 normalization scheme to convert all these into a standard form as
3298 well, and GCC will warn if your code is not in NFKC if you use
3299 @option{-Wnormalized=nfkc}. This warning is comparable to warning
3300 about every identifier that contains the letter O because it might be
3301 confused with the digit 0, and so is not the default, but may be
3302 useful as a local coding convention if the programming environment is
3303 unable to be fixed to display these characters distinctly.
3305 @item -Wno-deprecated-declarations
3306 @opindex Wno-deprecated-declarations
3307 Do not warn about uses of functions (@pxref{Function Attributes}),
3308 variables (@pxref{Variable Attributes}), and types (@pxref{Type
3309 Attributes}) marked as deprecated by using the @code{deprecated}
3313 @opindex Wno-overflow
3314 Do not warn about compile-time overflow in constant expressions.
3316 @item -Woverride-init
3317 @opindex Woverride-init
3320 Warn if an initialized field without side effects is overridden when
3321 using designated initializers (@pxref{Designated Inits, , Designated
3324 This warning is included in @option{-Wextra}. To get other
3325 @option{-Wextra} warnings without this one, use @samp{-Wextra
3326 -Wno-override-init}.
3330 Warn if a structure is given the packed attribute, but the packed
3331 attribute has no effect on the layout or size of the structure.
3332 Such structures may be mis-aligned for little benefit. For
3333 instance, in this code, the variable @code{f.x} in @code{struct bar}
3334 will be misaligned even though @code{struct bar} does not itself
3335 have the packed attribute:
3342 @} __attribute__((packed));
3352 Warn if padding is included in a structure, either to align an element
3353 of the structure or to align the whole structure. Sometimes when this
3354 happens it is possible to rearrange the fields of the structure to
3355 reduce the padding and so make the structure smaller.
3357 @item -Wredundant-decls
3358 @opindex Wredundant-decls
3359 Warn if anything is declared more than once in the same scope, even in
3360 cases where multiple declaration is valid and changes nothing.
3362 @item -Wnested-externs @r{(C only)}
3363 @opindex Wnested-externs
3364 Warn if an @code{extern} declaration is encountered within a function.
3366 @item -Wunreachable-code
3367 @opindex Wunreachable-code
3368 Warn if the compiler detects that code will never be executed.
3370 This option is intended to warn when the compiler detects that at
3371 least a whole line of source code will never be executed, because
3372 some condition is never satisfied or because it is after a
3373 procedure that never returns.
3375 It is possible for this option to produce a warning even though there
3376 are circumstances under which part of the affected line can be executed,
3377 so care should be taken when removing apparently-unreachable code.
3379 For instance, when a function is inlined, a warning may mean that the
3380 line is unreachable in only one inlined copy of the function.
3382 This option is not made part of @option{-Wall} because in a debugging
3383 version of a program there is often substantial code which checks
3384 correct functioning of the program and is, hopefully, unreachable
3385 because the program does work. Another common use of unreachable
3386 code is to provide behavior which is selectable at compile-time.
3390 Warn if a function can not be inlined and it was declared as inline.
3391 Even with this option, the compiler will not warn about failures to
3392 inline functions declared in system headers.
3394 The compiler uses a variety of heuristics to determine whether or not
3395 to inline a function. For example, the compiler takes into account
3396 the size of the function being inlined and the amount of inlining
3397 that has already been done in the current function. Therefore,
3398 seemingly insignificant changes in the source program can cause the
3399 warnings produced by @option{-Winline} to appear or disappear.
3401 @item -Wno-invalid-offsetof @r{(C++ only)}
3402 @opindex Wno-invalid-offsetof
3403 Suppress warnings from applying the @samp{offsetof} macro to a non-POD
3404 type. According to the 1998 ISO C++ standard, applying @samp{offsetof}
3405 to a non-POD type is undefined. In existing C++ implementations,
3406 however, @samp{offsetof} typically gives meaningful results even when
3407 applied to certain kinds of non-POD types. (Such as a simple
3408 @samp{struct} that fails to be a POD type only by virtue of having a
3409 constructor.) This flag is for users who are aware that they are
3410 writing nonportable code and who have deliberately chosen to ignore the
3413 The restrictions on @samp{offsetof} may be relaxed in a future version
3414 of the C++ standard.
3416 @item -Wno-int-to-pointer-cast @r{(C only)}
3417 @opindex Wno-int-to-pointer-cast
3418 Suppress warnings from casts to pointer type of an integer of a
3421 @item -Wno-pointer-to-int-cast @r{(C only)}
3422 @opindex Wno-pointer-to-int-cast
3423 Suppress warnings from casts from a pointer to an integer type of a
3427 @opindex Winvalid-pch
3428 Warn if a precompiled header (@pxref{Precompiled Headers}) is found in
3429 the search path but can't be used.
3433 @opindex Wno-long-long
3434 Warn if @samp{long long} type is used. This is default. To inhibit
3435 the warning messages, use @option{-Wno-long-long}. Flags
3436 @option{-Wlong-long} and @option{-Wno-long-long} are taken into account
3437 only when @option{-pedantic} flag is used.
3439 @item -Wvariadic-macros
3440 @opindex Wvariadic-macros
3441 @opindex Wno-variadic-macros
3442 Warn if variadic macros are used in pedantic ISO C90 mode, or the GNU
3443 alternate syntax when in pedantic ISO C99 mode. This is default.
3444 To inhibit the warning messages, use @option{-Wno-variadic-macros}.
3446 @item -Wvolatile-register-var
3447 @opindex Wvolatile-register-var
3448 @opindex Wno-volatile-register-var
3449 Warn if a register variable is declared volatile. The volatile
3450 modifier does not inhibit all optimizations that may eliminate reads
3451 and/or writes to register variables.
3453 @item -Wdisabled-optimization
3454 @opindex Wdisabled-optimization
3455 Warn if a requested optimization pass is disabled. This warning does
3456 not generally indicate that there is anything wrong with your code; it
3457 merely indicates that GCC's optimizers were unable to handle the code
3458 effectively. Often, the problem is that your code is too big or too
3459 complex; GCC will refuse to optimize programs when the optimization
3460 itself is likely to take inordinate amounts of time.
3462 @item -Wpointer-sign
3463 @opindex Wpointer-sign
3464 @opindex Wno-pointer-sign
3465 Warn for pointer argument passing or assignment with different signedness.
3466 This option is only supported for C and Objective-C@. It is implied by
3467 @option{-Wall} and by @option{-pedantic}, which can be disabled with
3468 @option{-Wno-pointer-sign}.
3472 Make all warnings into errors.
3476 Make the specified warning into an errors. The specifier for a
3477 warning is appended, for example @option{-Werror=switch} turns the
3478 warnings controlled by @option{-Wswitch} into errors. This switch
3479 takes a negative form, to be used to negate @option{-Werror} for
3480 specific warnings, for example @option{-Wno-error=switch} makes
3481 @option{-Wswitch} warnings not be errors, even when @option{-Werror}
3482 is in effect. You can use the @option{-fdiagnostics-show-option}
3483 option to have each controllable warning amended with the option which
3484 controls it, to determine what to use with this option.
3486 Note that specifying @option{-Werror=}@var{foo} automatically implies
3487 @option{-W}@var{foo}. However, @option{-Wno-error=}@var{foo} does not
3490 @item -Wstack-protector
3491 @opindex Wstack-protector
3492 This option is only active when @option{-fstack-protector} is active. It
3493 warns about functions that will not be protected against stack smashing.
3495 @item -Wstring-literal-comparison
3496 @opindex Wstring-literal-comparison
3497 Warn about suspicious comparisons to string literal constants. In C,
3498 direct comparisons against the memory address of a string literal, such
3499 as @code{if (x == "abc")}, typically indicate a programmer error, and
3500 even when intentional, result in unspecified behavior and are not portable.
3501 Usually these warnings alert that the programmer intended to use
3502 @code{strcmp}. This warning is enabled by @option{-Wall}.
3504 @item -Woverlength-strings
3505 @opindex Woverlength-strings
3506 Warn about string constants which are longer than the ``minimum
3507 maximum'' length specified in the C standard. Modern compilers
3508 generally allow string constants which are much longer than the
3509 standard's minimum limit, but very portable programs should avoid
3510 using longer strings.
3512 The limit applies @emph{after} string constant concatenation, and does
3513 not count the trailing NUL@. In C89, the limit was 509 characters; in
3514 C99, it was raised to 4095. C++98 does not specify a normative
3515 minimum maximum, so we do not diagnose overlength strings in C++@.
3517 This option is implied by @option{-pedantic}, and can be disabled with
3518 @option{-Wno-overlength-strings}.
3521 @node Debugging Options
3522 @section Options for Debugging Your Program or GCC
3523 @cindex options, debugging
3524 @cindex debugging information options
3526 GCC has various special options that are used for debugging
3527 either your program or GCC:
3532 Produce debugging information in the operating system's native format
3533 (stabs, COFF, XCOFF, or DWARF 2)@. GDB can work with this debugging
3536 On most systems that use stabs format, @option{-g} enables use of extra
3537 debugging information that only GDB can use; this extra information
3538 makes debugging work better in GDB but will probably make other debuggers
3540 refuse to read the program. If you want to control for certain whether
3541 to generate the extra information, use @option{-gstabs+}, @option{-gstabs},
3542 @option{-gxcoff+}, @option{-gxcoff}, or @option{-gvms} (see below).
3544 GCC allows you to use @option{-g} with
3545 @option{-O}. The shortcuts taken by optimized code may occasionally
3546 produce surprising results: some variables you declared may not exist
3547 at all; flow of control may briefly move where you did not expect it;
3548 some statements may not be executed because they compute constant
3549 results or their values were already at hand; some statements may
3550 execute in different places because they were moved out of loops.
3552 Nevertheless it proves possible to debug optimized output. This makes
3553 it reasonable to use the optimizer for programs that might have bugs.
3555 The following options are useful when GCC is generated with the
3556 capability for more than one debugging format.
3560 Produce debugging information for use by GDB@. This means to use the
3561 most expressive format available (DWARF 2, stabs, or the native format
3562 if neither of those are supported), including GDB extensions if at all
3567 Produce debugging information in stabs format (if that is supported),
3568 without GDB extensions. This is the format used by DBX on most BSD
3569 systems. On MIPS, Alpha and System V Release 4 systems this option
3570 produces stabs debugging output which is not understood by DBX or SDB@.
3571 On System V Release 4 systems this option requires the GNU assembler.
3573 @item -feliminate-unused-debug-symbols
3574 @opindex feliminate-unused-debug-symbols
3575 Produce debugging information in stabs format (if that is supported),
3576 for only symbols that are actually used.
3578 @item -femit-class-debug-always
3579 Instead of emitting debugging information for a C++ class in only one
3580 object file, emit it in all object files using the class. This option
3581 should be used only with debuggers that are unable to handle the way GCC
3582 normally emits debugging information for classes because using this
3583 option will increase the size of debugging information by as much as a
3588 Produce debugging information in stabs format (if that is supported),
3589 using GNU extensions understood only by the GNU debugger (GDB)@. The
3590 use of these extensions is likely to make other debuggers crash or
3591 refuse to read the program.
3595 Produce debugging information in COFF format (if that is supported).
3596 This is the format used by SDB on most System V systems prior to
3601 Produce debugging information in XCOFF format (if that is supported).
3602 This is the format used by the DBX debugger on IBM RS/6000 systems.
3606 Produce debugging information in XCOFF format (if that is supported),
3607 using GNU extensions understood only by the GNU debugger (GDB)@. The
3608 use of these extensions is likely to make other debuggers crash or
3609 refuse to read the program, and may cause assemblers other than the GNU
3610 assembler (GAS) to fail with an error.
3614 Produce debugging information in DWARF version 2 format (if that is
3615 supported). This is the format used by DBX on IRIX 6. With this
3616 option, GCC uses features of DWARF version 3 when they are useful;
3617 version 3 is upward compatible with version 2, but may still cause
3618 problems for older debuggers.