| @c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
| @c 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. |
| @c This is part of the GCC manual. |
| @c For copying conditions, see the file gcc.texi. |
| |
| @ignore |
| @c man begin COPYRIGHT |
| Copyright @copyright{} 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, |
| 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. |
| |
| Permission is granted to copy, distribute and/or modify this document |
| under the terms of the GNU Free Documentation License, Version 1.2 or |
| any later version published by the Free Software Foundation; with the |
| Invariant Sections being ``GNU General Public License'' and ``Funding |
| Free Software'', the Front-Cover texts being (a) (see below), and with |
| the Back-Cover Texts being (b) (see below). A copy of the license is |
| included in the gfdl(7) man page. |
| |
| (a) The FSF's Front-Cover Text is: |
| |
| A GNU Manual |
| |
| (b) The FSF's Back-Cover Text is: |
| |
| You have freedom to copy and modify this GNU Manual, like GNU |
| software. Copies published by the Free Software Foundation raise |
| funds for GNU development. |
| @c man end |
| @c Set file name and title for the man page. |
| @setfilename gcc |
| @settitle GNU project C and C++ compiler |
| @c man begin SYNOPSIS |
| gcc [@option{-c}|@option{-S}|@option{-E}] [@option{-std=}@var{standard}] |
| [@option{-g}] [@option{-pg}] [@option{-O}@var{level}] |
| [@option{-W}@var{warn}@dots{}] [@option{-pedantic}] |
| [@option{-I}@var{dir}@dots{}] [@option{-L}@var{dir}@dots{}] |
| [@option{-D}@var{macro}[=@var{defn}]@dots{}] [@option{-U}@var{macro}] |
| [@option{-f}@var{option}@dots{}] [@option{-m}@var{machine-option}@dots{}] |
| [@option{-o} @var{outfile}] @var{infile}@dots{} |
| |
| Only the most useful options are listed here; see below for the |
| remainder. @samp{g++} accepts mostly the same options as @samp{gcc}. |
| @c man end |
| @c man begin SEEALSO |
| gpl(7), gfdl(7), fsf-funding(7), |
| cpp(1), gcov(1), g77(1), as(1), ld(1), gdb(1), adb(1), dbx(1), sdb(1) |
| and the Info entries for @file{gcc}, @file{cpp}, @file{g77}, @file{as}, |
| @file{ld}, @file{binutils} and @file{gdb}. |
| @c man end |
| @c man begin BUGS |
| For instructions on reporting bugs, see |
| @w{@uref{http://gcc.gnu.org/bugs.html}}. Use of the @command{gccbug} |
| script to report bugs is recommended. |
| @c man end |
| @c man begin AUTHOR |
| See the Info entry for @command{gcc}, or |
| @w{@uref{http://gcc.gnu.org/onlinedocs/gcc/Contributors.html}}, |
| for contributors to GCC@. |
| @c man end |
| @end ignore |
| |
| @node Invoking GCC |
| @chapter GCC Command Options |
| @cindex GCC command options |
| @cindex command options |
| @cindex options, GCC command |
| |
| @c man begin DESCRIPTION |
| When you invoke GCC, it normally does preprocessing, compilation, |
| assembly and linking. The ``overall options'' allow you to stop this |
| process at an intermediate stage. For example, the @option{-c} option |
| says not to run the linker. Then the output consists of object files |
| output by the assembler. |
| |
| Other options are passed on to one stage of processing. Some options |
| control the preprocessor and others the compiler itself. Yet other |
| options control the assembler and linker; most of these are not |
| documented here, since you rarely need to use any of them. |
| |
| @cindex C compilation options |
| Most of the command line options that you can use with GCC are useful |
| for C programs; when an option is only useful with another language |
| (usually C++), the explanation says so explicitly. If the description |
| for a particular option does not mention a source language, you can use |
| that option with all supported languages. |
| |
| @cindex C++ compilation options |
| @xref{Invoking G++,,Compiling C++ Programs}, for a summary of special |
| options for compiling C++ programs. |
| |
| @cindex grouping options |
| @cindex options, grouping |
| The @command{gcc} program accepts options and file names as operands. Many |
| options have multi-letter names; therefore multiple single-letter options |
| may @emph{not} be grouped: @option{-dr} is very different from @w{@samp{-d |
| -r}}. |
| |
| @cindex order of options |
| @cindex options, order |
| You can mix options and other arguments. For the most part, the order |
| you use doesn't matter. Order does matter when you use several options |
| of the same kind; for example, if you specify @option{-L} more than once, |
| the directories are searched in the order specified. |
| |
| Many options have long names starting with @samp{-f} or with |
| @samp{-W}---for example, @option{-fforce-mem}, |
| @option{-fstrength-reduce}, @option{-Wformat} and so on. Most of |
| these have both positive and negative forms; the negative form of |
| @option{-ffoo} would be @option{-fno-foo}. This manual documents |
| only one of these two forms, whichever one is not the default. |
| |
| @c man end |
| |
| @xref{Option Index}, for an index to GCC's options. |
| |
| @menu |
| * Option Summary:: Brief list of all options, without explanations. |
| * Overall Options:: Controlling the kind of output: |
| an executable, object files, assembler files, |
| or preprocessed source. |
| * Invoking G++:: Compiling C++ programs. |
| * C Dialect Options:: Controlling the variant of C language compiled. |
| * C++ Dialect Options:: Variations on C++. |
| * Objective-C Dialect Options:: Variations on Objective-C. |
| * Language Independent Options:: Controlling how diagnostics should be |
| formatted. |
| * Warning Options:: How picky should the compiler be? |
| * Debugging Options:: Symbol tables, measurements, and debugging dumps. |
| * Optimize Options:: How much optimization? |
| * Preprocessor Options:: Controlling header files and macro definitions. |
| Also, getting dependency information for Make. |
| * Assembler Options:: Passing options to the assembler. |
| * Link Options:: Specifying libraries and so on. |
| * Directory Options:: Where to find header files and libraries. |
| Where to find the compiler executable files. |
| * Spec Files:: How to pass switches to sub-processes. |
| * Target Options:: Running a cross-compiler, or an old version of GCC. |
| * Submodel Options:: Specifying minor hardware or convention variations, |
| such as 68010 vs 68020. |
| * Code Gen Options:: Specifying conventions for function calls, data layout |
| and register usage. |
| * Environment Variables:: Env vars that affect GCC. |
| * Precompiled Headers:: Compiling a header once, and using it many times. |
| * Running Protoize:: Automatically adding or removing function prototypes. |
| @end menu |
| |
| @c man begin OPTIONS |
| |
| @node Option Summary |
| @section Option Summary |
| |
| Here is a summary of all the options, grouped by type. Explanations are |
| in the following sections. |
| |
| @table @emph |
| @item Overall Options |
| @xref{Overall Options,,Options Controlling the Kind of Output}. |
| @gccoptlist{-c -S -E -o @var{file} -pipe -pass-exit-codes @gol |
| -x @var{language} -v -### --help --target-help --version} |
| |
| @item C Language Options |
| @xref{C Dialect Options,,Options Controlling C Dialect}. |
| @gccoptlist{-ansi -std=@var{standard} -aux-info @var{filename} @gol |
| -fno-asm -fno-builtin -fno-builtin-@var{function} @gol |
| -fhosted -ffreestanding -fms-extensions @gol |
| -trigraphs -no-integrated-cpp -traditional -traditional-cpp @gol |
| -fallow-single-precision -fcond-mismatch @gol |
| -fsigned-bitfields -fsigned-char @gol |
| -funsigned-bitfields -funsigned-char @gol |
| -fwritable-strings} |
| |
| @item C++ Language Options |
| @xref{C++ Dialect Options,,Options Controlling C++ Dialect}. |
| @gccoptlist{-fabi-version=@var{n} -fno-access-control -fcheck-new @gol |
| -fconserve-space -fno-const-strings @gol |
| -fno-elide-constructors @gol |
| -fno-enforce-eh-specs @gol |
| -ffor-scope -fno-for-scope -fno-gnu-keywords @gol |
| -fno-implicit-templates @gol |
| -fno-implicit-inline-templates @gol |
| -fno-implement-inlines -fms-extensions @gol |
| -fno-nonansi-builtins -fno-operator-names @gol |
| -fno-optional-diags -fpermissive @gol |
| -frepo -fno-rtti -fstats -ftemplate-depth-@var{n} @gol |
| -fuse-cxa-atexit -fno-weak -nostdinc++ @gol |
| -fno-default-inline -Wabi -Wctor-dtor-privacy @gol |
| -Wnon-virtual-dtor -Wreorder @gol |
| -Weffc++ -Wno-deprecated @gol |
| -Wno-non-template-friend -Wold-style-cast @gol |
| -Woverloaded-virtual -Wno-pmf-conversions @gol |
| -Wsign-promo -Wsynth} |
| |
| @item Objective-C Language Options |
| @xref{Objective-C Dialect Options,,Options Controlling Objective-C Dialect}. |
| @gccoptlist{ |
| -fconstant-string-class=@var{class-name} @gol |
| -fgnu-runtime -fnext-runtime @gol |
| -fno-nil-receivers @gol |
| -fobjc-exceptions @gol |
| -freplace-objc-classes @gol |
| -fzero-link @gol |
| -gen-decls @gol |
| -Wno-protocol -Wselector -Wundeclared-selector} |
| |
| @item Language Independent Options |
| @xref{Language Independent Options,,Options to Control Diagnostic Messages Formatting}. |
| @gccoptlist{-fmessage-length=@var{n} @gol |
| -fdiagnostics-show-location=@r{[}once@r{|}every-line@r{]}} |
| |
| @item Warning Options |
| @xref{Warning Options,,Options to Request or Suppress Warnings}. |
| @gccoptlist{-fsyntax-only -pedantic -pedantic-errors @gol |
| -w -Wextra -Wall -Waggregate-return @gol |
| -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment @gol |
| -Wconversion -Wno-deprecated-declarations @gol |
| -Wdisabled-optimization -Wno-div-by-zero -Wendif-labels @gol |
| -Werror -Werror-implicit-function-declaration @gol |
| -Wfloat-equal -Wformat -Wformat=2 @gol |
| -Wno-format-extra-args -Wformat-nonliteral @gol |
| -Wformat-security -Wformat-y2k @gol |
| -Wimplicit -Wimplicit-function-declaration -Wimplicit-int @gol |
| -Wimport -Wno-import -Winit-self -Winline @gol |
| -Wno-invalid-offsetof -Winvalid-pch @gol |
| -Wlarger-than-@var{len} -Wlong-long @gol |
| -Wmain -Wmissing-braces @gol |
| -Wmissing-format-attribute -Wmissing-noreturn @gol |
| -Wno-multichar -Wnonnull -Wpacked -Wpadded @gol |
| -Wparentheses -Wpointer-arith -Wredundant-decls @gol |
| -Wreturn-type -Wsequence-point -Wshadow @gol |
| -Wsign-compare -Wstrict-aliasing @gol |
| -Wswitch -Wswitch-default -Wswitch-enum @gol |
| -Wsystem-headers -Wtrigraphs -Wundef -Wuninitialized @gol |
| -Wunknown-pragmas -Wunreachable-code @gol |
| -Wunused -Wunused-function -Wunused-label -Wunused-parameter @gol |
| -Wunused-value -Wunused-variable -Wwrite-strings} |
| |
| @item C-only Warning Options |
| @gccoptlist{-Wbad-function-cast -Wmissing-declarations @gol |
| -Wmissing-prototypes -Wnested-externs -Wold-style-definition @gol |
| -Wstrict-prototypes -Wtraditional @gol |
| -Wdeclaration-after-statement} |
| |
| @item Debugging Options |
| @xref{Debugging Options,,Options for Debugging Your Program or GCC}. |
| @gccoptlist{-d@var{letters} -dumpspecs -dumpmachine -dumpversion @gol |
| -fdump-unnumbered -fdump-translation-unit@r{[}-@var{n}@r{]} @gol |
| -fdump-class-hierarchy@r{[}-@var{n}@r{]} @gol |
| -fdump-tree-original@r{[}-@var{n}@r{]} @gol |
| -fdump-tree-optimized@r{[}-@var{n}@r{]} @gol |
| -fdump-tree-inlined@r{[}-@var{n}@r{]} @gol |
| -feliminate-dwarf2-dups -feliminate-unused-debug-types @gol |
| -feliminate-unused-debug-symbols -fmem-report -fprofile-arcs @gol |
| -frandom-seed=@var{string} -fsched-verbose=@var{n} @gol |
| -ftest-coverage -ftime-report @gol |
| -g -g@var{level} -gcoff -gdwarf-2 @gol |
| -ggdb -gstabs -gstabs+ -gvms -gxcoff -gxcoff+ @gol |
| -p -pg -print-file-name=@var{library} -print-libgcc-file-name @gol |
| -print-multi-directory -print-multi-lib @gol |
| -print-prog-name=@var{program} -print-search-dirs -Q @gol |
| -save-temps -time} |
| |
| @item Optimization Options |
| @xref{Optimize Options,,Options that Control Optimization}. |
| @gccoptlist{-falign-functions=@var{n} -falign-jumps=@var{n} @gol |
| -falign-labels=@var{n} -falign-loops=@var{n} @gol |
| -fbranch-probabilities -fprofile-values -fvpt -fbranch-target-load-optimize @gol |
| -fbranch-target-load-optimize2 -fcaller-saves -fcprop-registers @gol |
| -fcse-follow-jumps -fcse-skip-blocks -fdata-sections @gol |
| -fdelayed-branch -fdelete-null-pointer-checks @gol |
| -fexpensive-optimizations -ffast-math -ffloat-store @gol |
| -fforce-addr -fforce-mem -ffunction-sections @gol |
| -fgcse -fgcse-lm -fgcse-sm -fgcse-las -floop-optimize @gol |
| -fcrossjumping -fif-conversion -fif-conversion2 @gol |
| -finline-functions -finline-limit=@var{n} -fkeep-inline-functions @gol |
| -fkeep-static-consts -fmerge-constants -fmerge-all-constants @gol |
| -fmove-all-movables -fnew-ra -fno-branch-count-reg @gol |
| -fno-default-inline -fno-defer-pop @gol |
| -fno-function-cse -fno-guess-branch-probability @gol |
| -fno-inline -fno-math-errno -fno-peephole -fno-peephole2 @gol |
| -funsafe-math-optimizations -ffinite-math-only @gol |
| -fno-trapping-math -fno-zero-initialized-in-bss @gol |
| -fomit-frame-pointer -foptimize-register-move @gol |
| -foptimize-sibling-calls -fprefetch-loop-arrays @gol |
| -fprofile-generate -fprofile-use @gol |
| -freduce-all-givs -fregmove -frename-registers @gol |
| -freorder-blocks -freorder-functions @gol |
| -frerun-cse-after-loop -frerun-loop-opt @gol |
| -frounding-math -fschedule-insns -fschedule-insns2 @gol |
| -fno-sched-interblock -fno-sched-spec -fsched-spec-load @gol |
| -fsched-spec-load-dangerous @gol |
| -fsched-stalled-insns=@var{n} -sched-stalled-insns-dep=@var{n} @gol |
| -fsched2-use-superblocks @gol |
| -fsched2-use-traces -fsignaling-nans @gol |
| -fsingle-precision-constant @gol |
| -fstrength-reduce -fstrict-aliasing -ftracer -fthread-jumps @gol |
| -funroll-all-loops -funroll-loops -fpeel-loops @gol |
| -funswitch-loops -fold-unroll-loops -fold-unroll-all-loops @gol |
| --param @var{name}=@var{value} |
| -O -O0 -O1 -O2 -O3 -Os} |
| |
| @item Preprocessor Options |
| @xref{Preprocessor Options,,Options Controlling the Preprocessor}. |
| @gccoptlist{-A@var{question}=@var{answer} @gol |
| -A-@var{question}@r{[}=@var{answer}@r{]} @gol |
| -C -dD -dI -dM -dN @gol |
| -D@var{macro}@r{[}=@var{defn}@r{]} -E -H @gol |
| -idirafter @var{dir} @gol |
| -include @var{file} -imacros @var{file} @gol |
| -iprefix @var{file} -iwithprefix @var{dir} @gol |
| -iwithprefixbefore @var{dir} -isystem @var{dir} @gol |
| -M -MM -MF -MG -MP -MQ -MT -nostdinc @gol |
| -P -fworking-directory -remap @gol |
| -trigraphs -undef -U@var{macro} -Wp,@var{option} @gol |
| -Xpreprocessor @var{option}} |
| |
| @item Assembler Option |
| @xref{Assembler Options,,Passing Options to the Assembler}. |
| @gccoptlist{-Wa,@var{option} -Xassembler @var{option}} |
| |
| @item Linker Options |
| @xref{Link Options,,Options for Linking}. |
| @gccoptlist{@var{object-file-name} -l@var{library} @gol |
| -nostartfiles -nodefaultlibs -nostdlib -pie @gol |
| -s -static -static-libgcc -shared -shared-libgcc -symbolic @gol |
| -Wl,@var{option} -Xlinker @var{option} @gol |
| -u @var{symbol}} |
| |
| @item Directory Options |
| @xref{Directory Options,,Options for Directory Search}. |
| @gccoptlist{-B@var{prefix} -I@var{dir} -I- -L@var{dir} -specs=@var{file}} |
| |
| @item Target Options |
| @c I wrote this xref this way to avoid overfull hbox. -- rms |
| @xref{Target Options}. |
| @gccoptlist{-V @var{version} -b @var{machine}} |
| |
| @item Machine Dependent Options |
| @xref{Submodel Options,,Hardware Models and Configurations}. |
| |
| @emph{M680x0 Options} |
| @gccoptlist{-m68000 -m68020 -m68020-40 -m68020-60 -m68030 -m68040 @gol |
| -m68060 -mcpu32 -m5200 -m68881 -mbitfield -mc68000 -mc68020 @gol |
| -mnobitfield -mrtd -mshort -msoft-float -mpcrel @gol |
| -malign-int -mstrict-align -msep-data -mno-sep-data @gol |
| -mshared-library-id=n -mid-shared-library -mno-id-shared-library} |
| |
| @emph{M68hc1x Options} |
| @gccoptlist{-m6811 -m6812 -m68hc11 -m68hc12 -m68hcs12 @gol |
| -mauto-incdec -minmax -mlong-calls -mshort @gol |
| -msoft-reg-count=@var{count}} |
| |
| @emph{VAX Options} |
| @gccoptlist{-mg -mgnu -munix} |
| |
| @emph{SPARC Options} |
| @gccoptlist{-mcpu=@var{cpu-type} @gol |
| -mtune=@var{cpu-type} @gol |
| -mcmodel=@var{code-model} @gol |
| -m32 -m64 -mapp-regs -mno-app-regs @gol |
| -mfaster-structs -mno-faster-structs @gol |
| -mflat -mno-flat -mfpu -mno-fpu @gol |
| -mhard-float -msoft-float @gol |
| -mhard-quad-float -msoft-quad-float @gol |
| -mimpure-text -mno-impure-text -mlittle-endian @gol |
| -mstack-bias -mno-stack-bias @gol |
| -munaligned-doubles -mno-unaligned-doubles @gol |
| -mv8plus -mno-v8plus -mvis -mno-vis @gol |
| -mcypress -mf930 -mf934 @gol |
| -msparclite -msupersparc -mv8 |
| -threads -pthreads} |
| |
| @emph{ARM Options} |
| @gccoptlist{-mapcs-frame -mno-apcs-frame @gol |
| -mapcs-26 -mapcs-32 @gol |
| -mapcs-stack-check -mno-apcs-stack-check @gol |
| -mapcs-float -mno-apcs-float @gol |
| -mapcs-reentrant -mno-apcs-reentrant @gol |
| -msched-prolog -mno-sched-prolog @gol |
| -mlittle-endian -mbig-endian -mwords-little-endian @gol |
| -malignment-traps -mno-alignment-traps @gol |
| -msoft-float -mhard-float -mfpe @gol |
| -mthumb-interwork -mno-thumb-interwork @gol |
| -mcpu=@var{name} -march=@var{name} -mfpe=@var{name} @gol |
| -mstructure-size-boundary=@var{n} @gol |
| -mabort-on-noreturn @gol |
| -mlong-calls -mno-long-calls @gol |
| -msingle-pic-base -mno-single-pic-base @gol |
| -mpic-register=@var{reg} @gol |
| -mnop-fun-dllimport @gol |
| -mcirrus-fix-invalid-insns -mno-cirrus-fix-invalid-insns @gol |
| -mpoke-function-name @gol |
| -mthumb -marm @gol |
| -mtpcs-frame -mtpcs-leaf-frame @gol |
| -mcaller-super-interworking -mcallee-super-interworking} |
| |
| @emph{MN10300 Options} |
| @gccoptlist{-mmult-bug -mno-mult-bug @gol |
| -mam33 -mno-am33 @gol |
| -mam33-2 -mno-am33-2 @gol |
| -mno-crt0 -mrelax} |
| |
| @emph{M32R/D Options} |
| @gccoptlist{-m32r2 -m32rx -m32r @gol |
| -mdebug @gol |
| -malign-loops -mno-align-loops @gol |
| -missue-rate=@var{number} @gol |
| -mbranch-cost=@var{number} @gol |
| -mmodel=@var{code-size-model-type} @gol |
| -msdata=@var{sdata-type} @gol |
| -mno-flush-func -mflush-func=@var{name} @gol |
| -mno-flush-trap -mflush-trap=@var{number} @gol |
| -G @var{num}} |
| |
| @emph{RS/6000 and PowerPC Options} |
| @gccoptlist{-mcpu=@var{cpu-type} @gol |
| -mtune=@var{cpu-type} @gol |
| -mpower -mno-power -mpower2 -mno-power2 @gol |
| -mpowerpc -mpowerpc64 -mno-powerpc @gol |
| -maltivec -mno-altivec @gol |
| -mpowerpc-gpopt -mno-powerpc-gpopt @gol |
| -mpowerpc-gfxopt -mno-powerpc-gfxopt @gol |
| -mnew-mnemonics -mold-mnemonics @gol |
| -mfull-toc -mminimal-toc -mno-fp-in-toc -mno-sum-in-toc @gol |
| -m64 -m32 -mxl-call -mno-xl-call -mpe @gol |
| -malign-power -malign-natural @gol |
| -msoft-float -mhard-float -mmultiple -mno-multiple @gol |
| -mstring -mno-string -mupdate -mno-update @gol |
| -mfused-madd -mno-fused-madd -mbit-align -mno-bit-align @gol |
| -mstrict-align -mno-strict-align -mrelocatable @gol |
| -mno-relocatable -mrelocatable-lib -mno-relocatable-lib @gol |
| -mtoc -mno-toc -mlittle -mlittle-endian -mbig -mbig-endian @gol |
| -mdynamic-no-pic @gol |
| -mprioritize-restricted-insns=@var{priority} @gol |
| -msched-costly-dep=@var{dependence_type} @gol |
| -minsert-sched-nops=@var{scheme} @gol |
| -mcall-sysv -mcall-netbsd @gol |
| -maix-struct-return -msvr4-struct-return @gol |
| -mabi=altivec -mabi=no-altivec @gol |
| -mabi=spe -mabi=no-spe @gol |
| -misel=yes -misel=no @gol |
| -mspe=yes -mspe=no @gol |
| -mfloat-gprs=yes -mfloat-gprs=no @gol |
| -mprototype -mno-prototype @gol |
| -msim -mmvme -mads -myellowknife -memb -msdata @gol |
| -msdata=@var{opt} -mvxworks -mwindiss -G @var{num} -pthread} |
| |
| @emph{Darwin Options} |
| @gccoptlist{-all_load -allowable_client -arch -arch_errors_fatal @gol |
| -arch_only -bind_at_load -bundle -bundle_loader @gol |
| -client_name -compatibility_version -current_version @gol |
| -dependency-file -dylib_file -dylinker_install_name @gol |
| -dynamic -dynamiclib -exported_symbols_list @gol |
| -filelist -flat_namespace -force_cpusubtype_ALL @gol |
| -force_flat_namespace -headerpad_max_install_names @gol |
| -image_base -init -install_name -keep_private_externs @gol |
| -multi_module -multiply_defined -multiply_defined_unused @gol |
| -noall_load -nofixprebinding -nomultidefs -noprebind -noseglinkedit @gol |
| -pagezero_size -prebind -prebind_all_twolevel_modules @gol |
| -private_bundle -read_only_relocs -sectalign @gol |
| -sectobjectsymbols -whyload -seg1addr @gol |
| -sectcreate -sectobjectsymbols -sectorder @gol |
| -seg_addr_table -seg_addr_table_filename -seglinkedit @gol |
| -segprot -segs_read_only_addr -segs_read_write_addr @gol |
| -single_module -static -sub_library -sub_umbrella @gol |
| -twolevel_namespace -umbrella -undefined @gol |
| -unexported_symbols_list -weak_reference_mismatches @gol |
| -whatsloaded} |
| |
| @emph{MIPS Options} |
| @gccoptlist{-EL -EB -march=@var{arch} -mtune=@var{arch} @gol |
| -mips1 -mips2 -mips3 -mips4 -mips32 -mips32r2 -mips64 @gol |
| -mips16 -mno-mips16 -mabi=@var{abi} -mabicalls -mno-abicalls @gol |
| -mxgot -mno-xgot -membedded-pic -mno-embedded-pic @gol |
| -mgp32 -mgp64 -mfp32 -mfp64 -mhard-float -msoft-float @gol |
| -msingle-float -mdouble-float -mint64 -mlong64 -mlong32 @gol |
| -G@var{num} -membedded-data -mno-embedded-data @gol |
| -muninit-const-in-rodata -mno-uninit-const-in-rodata @gol |
| -msplit-addresses -mno-split-addresses @gol |
| -mexplicit-relocs -mno-explicit-relocs @gol |
| -mrnames -mno-rnames @gol |
| -mcheck-zero-division -mno-check-zero-division @gol |
| -mmemcpy -mno-memcpy -mlong-calls -mno-long-calls @gol |
| -mmad -mno-mad -mfused-madd -mno-fused-madd -nocpp @gol |
| -mfix-sb1 -mno-fix-sb1 -mflush-func=@var{func} @gol |
| -mno-flush-func -mbranch-likely -mno-branch-likely} |
| |
| @emph{i386 and x86-64 Options} |
| @gccoptlist{-mtune=@var{cpu-type} -march=@var{cpu-type} @gol |
| -mfpmath=@var{unit} @gol |
| -masm=@var{dialect} -mno-fancy-math-387 @gol |
| -mno-fp-ret-in-387 -msoft-float -msvr3-shlib @gol |
| -mno-wide-multiply -mrtd -malign-double @gol |
| -mpreferred-stack-boundary=@var{num} @gol |
| -mmmx -msse -msse2 -msse3 -m3dnow @gol |
| -mthreads -mno-align-stringops -minline-all-stringops @gol |
| -mpush-args -maccumulate-outgoing-args -m128bit-long-double @gol |
| -m96bit-long-double -mregparm=@var{num} -momit-leaf-frame-pointer @gol |
| -mno-red-zone -mno-tls-direct-seg-refs @gol |
| -mcmodel=@var{code-model} @gol |
| -m32 -m64} |
| |
| @emph{HPPA Options} |
| @gccoptlist{-march=@var{architecture-type} @gol |
| -mbig-switch -mdisable-fpregs -mdisable-indexing @gol |
| -mfast-indirect-calls -mgas -mgnu-ld -mhp-ld @gol |
| -mjump-in-delay -mlinker-opt -mlong-calls @gol |
| -mlong-load-store -mno-big-switch -mno-disable-fpregs @gol |
| -mno-disable-indexing -mno-fast-indirect-calls -mno-gas @gol |
| -mno-jump-in-delay -mno-long-load-store @gol |
| -mno-portable-runtime -mno-soft-float @gol |
| -mno-space-regs -msoft-float -mpa-risc-1-0 @gol |
| -mpa-risc-1-1 -mpa-risc-2-0 -mportable-runtime @gol |
| -mschedule=@var{cpu-type} -mspace-regs -msio -mwsio @gol |
| -nolibdld -static -threads} |
| |
| @emph{Intel 960 Options} |
| @gccoptlist{-m@var{cpu-type} -masm-compat -mclean-linkage @gol |
| -mcode-align -mcomplex-addr -mleaf-procedures @gol |
| -mic-compat -mic2.0-compat -mic3.0-compat @gol |
| -mintel-asm -mno-clean-linkage -mno-code-align @gol |
| -mno-complex-addr -mno-leaf-procedures @gol |
| -mno-old-align -mno-strict-align -mno-tail-call @gol |
| -mnumerics -mold-align -msoft-float -mstrict-align @gol |
| -mtail-call} |
| |
| @emph{DEC Alpha Options} |
| @gccoptlist{-mno-fp-regs -msoft-float -malpha-as -mgas @gol |
| -mieee -mieee-with-inexact -mieee-conformant @gol |
| -mfp-trap-mode=@var{mode} -mfp-rounding-mode=@var{mode} @gol |
| -mtrap-precision=@var{mode} -mbuild-constants @gol |
| -mcpu=@var{cpu-type} -mtune=@var{cpu-type} @gol |
| -mbwx -mmax -mfix -mcix @gol |
| -mfloat-vax -mfloat-ieee @gol |
| -mexplicit-relocs -msmall-data -mlarge-data @gol |
| -msmall-text -mlarge-text @gol |
| -mmemory-latency=@var{time}} |
| |
| @emph{DEC Alpha/VMS Options} |
| @gccoptlist{-mvms-return-codes} |
| |
| @emph{H8/300 Options} |
| @gccoptlist{-mrelax -mh -ms -mn -mint32 -malign-300} |
| |
| @emph{SH Options} |
| @gccoptlist{-m1 -m2 -m2e -m3 -m3e @gol |
| -m4-nofpu -m4-single-only -m4-single -m4 @gol |
| -m5-64media -m5-64media-nofpu @gol |
| -m5-32media -m5-32media-nofpu @gol |
| -m5-compact -m5-compact-nofpu @gol |
| -mb -ml -mdalign -mrelax @gol |
| -mbigtable -mfmovd -mhitachi -mnomacsave @gol |
| -mieee -misize -mpadstruct -mspace @gol |
| -mprefergot -musermode} |
| |
| @emph{System V Options} |
| @gccoptlist{-Qy -Qn -YP,@var{paths} -Ym,@var{dir}} |
| |
| @emph{ARC Options} |
| @gccoptlist{-EB -EL @gol |
| -mmangle-cpu -mcpu=@var{cpu} -mtext=@var{text-section} @gol |
| -mdata=@var{data-section} -mrodata=@var{readonly-data-section}} |
| |
| @emph{TMS320C3x/C4x Options} |
| @gccoptlist{-mcpu=@var{cpu} -mbig -msmall -mregparm -mmemparm @gol |
| -mfast-fix -mmpyi -mbk -mti -mdp-isr-reload @gol |
| -mrpts=@var{count} -mrptb -mdb -mloop-unsigned @gol |
| -mparallel-insns -mparallel-mpy -mpreserve-float} |
| |
| @emph{V850 Options} |
| @gccoptlist{-mlong-calls -mno-long-calls -mep -mno-ep @gol |
| -mprolog-function -mno-prolog-function -mspace @gol |
| -mtda=@var{n} -msda=@var{n} -mzda=@var{n} @gol |
| -mapp-regs -mno-app-regs @gol |
| -mdisable-callt -mno-disable-callt @gol |
| -mv850e1 @gol |
| -mv850e @gol |
| -mv850 -mbig-switch} |
| |
| @emph{NS32K Options} |
| @gccoptlist{-m32032 -m32332 -m32532 -m32081 -m32381 @gol |
| -mmult-add -mnomult-add -msoft-float -mrtd -mnortd @gol |
| -mregparam -mnoregparam -msb -mnosb @gol |
| -mbitfield -mnobitfield -mhimem -mnohimem} |
| |
| @emph{AVR Options} |
| @gccoptlist{-mmcu=@var{mcu} -msize -minit-stack=@var{n} -mno-interrupts @gol |
| -mcall-prologues -mno-tablejump -mtiny-stack} |
| |
| @emph{MCore Options} |
| @gccoptlist{-mhardlit -mno-hardlit -mdiv -mno-div -mrelax-immediates @gol |
| -mno-relax-immediates -mwide-bitfields -mno-wide-bitfields @gol |
| -m4byte-functions -mno-4byte-functions -mcallgraph-data @gol |
| -mno-callgraph-data -mslow-bytes -mno-slow-bytes -mno-lsim @gol |
| -mlittle-endian -mbig-endian -m210 -m340 -mstack-increment} |
| |
| @emph{MMIX Options} |
| @gccoptlist{-mlibfuncs -mno-libfuncs -mepsilon -mno-epsilon -mabi=gnu @gol |
| -mabi=mmixware -mzero-extend -mknuthdiv -mtoplevel-symbols @gol |
| -melf -mbranch-predict -mno-branch-predict -mbase-addresses @gol |
| -mno-base-addresses -msingle-exit -mno-single-exit} |
| |
| @emph{IA-64 Options} |
| @gccoptlist{-mbig-endian -mlittle-endian -mgnu-as -mgnu-ld -mno-pic @gol |
| -mvolatile-asm-stop -mb-step -mregister-names -mno-sdata @gol |
| -mconstant-gp -mauto-pic -minline-float-divide-min-latency @gol |
| -minline-float-divide-max-throughput @gol |
| -minline-int-divide-min-latency @gol |
| -minline-int-divide-max-throughput -mno-dwarf2-asm @gol |
| -mfixed-range=@var{register-range}} |
| |
| @emph{D30V Options} |
| @gccoptlist{-mextmem -mextmemory -monchip -mno-asm-optimize @gol |
| -masm-optimize -mbranch-cost=@var{n} -mcond-exec=@var{n}} |
| |
| @emph{S/390 and zSeries Options} |
| @gccoptlist{-mtune=@var{cpu-type} -march=@var{cpu-type} @gol |
| -mhard-float -msoft-float -mbackchain -mno-backchain @gol |
| -msmall-exec -mno-small-exec -mmvcle -mno-mvcle @gol |
| -m64 -m31 -mdebug -mno-debug -mesa -mzarch -mfused-madd -mno-fused-madd} |
| |
| @emph{CRIS Options} |
| @gccoptlist{-mcpu=@var{cpu} -march=@var{cpu} -mtune=@var{cpu} @gol |
| -mmax-stack-frame=@var{n} -melinux-stacksize=@var{n} @gol |
| -metrax4 -metrax100 -mpdebug -mcc-init -mno-side-effects @gol |
| -mstack-align -mdata-align -mconst-align @gol |
| -m32-bit -m16-bit -m8-bit -mno-prologue-epilogue -mno-gotplt @gol |
| -melf -maout -melinux -mlinux -sim -sim2 @gol |
| -mmul-bug-workaround -mno-mul-bug-workaround} |
| |
| @emph{PDP-11 Options} |
| @gccoptlist{-mfpu -msoft-float -mac0 -mno-ac0 -m40 -m45 -m10 @gol |
| -mbcopy -mbcopy-builtin -mint32 -mno-int16 @gol |
| -mint16 -mno-int32 -mfloat32 -mno-float64 @gol |
| -mfloat64 -mno-float32 -mabshi -mno-abshi @gol |
| -mbranch-expensive -mbranch-cheap @gol |
| -msplit -mno-split -munix-asm -mdec-asm} |
| |
| @emph{Xstormy16 Options} |
| @gccoptlist{-msim} |
| |
| @emph{Xtensa Options} |
| @gccoptlist{-mconst16 -mno-const16 @gol |
| -mfused-madd -mno-fused-madd @gol |
| -mtext-section-literals -mno-text-section-literals @gol |
| -mtarget-align -mno-target-align @gol |
| -mlongcalls -mno-longcalls} |
| |
| @emph{FRV Options} |
| @gccoptlist{-mgpr-32 -mgpr-64 -mfpr-32 -mfpr-64 @gol |
| -mhard-float -msoft-float @gol |
| -malloc-cc -mfixed-cc -mdword -mno-dword @gol |
| -mdouble -mno-double @gol |
| -mmedia -mno-media -mmuladd -mno-muladd @gol |
| -mlibrary-pic -macc-4 -macc-8 @gol |
| -mpack -mno-pack -mno-eflags -mcond-move -mno-cond-move @gol |
| -mscc -mno-scc -mcond-exec -mno-cond-exec @gol |
| -mvliw-branch -mno-vliw-branch @gol |
| -mmulti-cond-exec -mno-multi-cond-exec -mnested-cond-exec @gol |
| -mno-nested-cond-exec -mtomcat-stats @gol |
| -mcpu=@var{cpu}} |
| |
| @item Code Generation Options |
| @xref{Code Gen Options,,Options for Code Generation Conventions}. |
| @gccoptlist{-fcall-saved-@var{reg} -fcall-used-@var{reg} @gol |
| -ffixed-@var{reg} -fexceptions @gol |
| -fnon-call-exceptions -funwind-tables @gol |
| -fasynchronous-unwind-tables @gol |
| -finhibit-size-directive -finstrument-functions @gol |
| -fno-common -fno-ident @gol |
| -fpcc-struct-return -fpic -fPIC -fpie -fPIE @gol |
| -freg-struct-return -fshared-data -fshort-enums @gol |
| -fshort-double -fshort-wchar @gol |
| -fverbose-asm -fpack-struct -fstack-check @gol |
| -fstack-limit-register=@var{reg} -fstack-limit-symbol=@var{sym} @gol |
| -fargument-alias -fargument-noalias @gol |
| -fargument-noalias-global -fleading-underscore @gol |
| -ftls-model=@var{model} @gol |
| -ftrapv -fwrapv -fbounds-check} |
| @end table |
| |
| @menu |
| * Overall Options:: Controlling the kind of output: |
| an executable, object files, assembler files, |
| or preprocessed source. |
| * C Dialect Options:: Controlling the variant of C language compiled. |
| * C++ Dialect Options:: Variations on C++. |
| * Objective-C Dialect Options:: Variations on Objective-C. |
| * Language Independent Options:: Controlling how diagnostics should be |
| formatted. |
| * Warning Options:: How picky should the compiler be? |
| * Debugging Options:: Symbol tables, measurements, and debugging dumps. |
| * Optimize Options:: How much optimization? |
| * Preprocessor Options:: Controlling header files and macro definitions. |
| Also, getting dependency information for Make. |
| * Assembler Options:: Passing options to the assembler. |
| * Link Options:: Specifying libraries and so on. |
| * Directory Options:: Where to find header files and libraries. |
| Where to find the compiler executable files. |
| * Spec Files:: How to pass switches to sub-processes. |
| * Target Options:: Running a cross-compiler, or an old version of GCC. |
| @end menu |
| |
| @node Overall Options |
| @section Options Controlling the Kind of Output |
| |
| Compilation can involve up to four stages: preprocessing, compilation |
| proper, assembly and linking, always in that order. GCC is capable of |
| preprocessing and compiling several files either into several |
| assembler input files, or into one assembler input file; then each |
| assembler input file produces an object file, and linking combines all |
| the object files (those newly compiled, and those specified as input) |
| into an executable file. |
| |
| @cindex file name suffix |
| For any given input file, the file name suffix determines what kind of |
| compilation is done: |
| |
| @table @gcctabopt |
| @item @var{file}.c |
| C source code which must be preprocessed. |
| |
| @item @var{file}.i |
| C source code which should not be preprocessed. |
| |
| @item @var{file}.ii |
| C++ source code which should not be preprocessed. |
| |
| @item @var{file}.m |
| Objective-C source code. Note that you must link with the library |
| @file{libobjc.a} to make an Objective-C program work. |
| |
| @item @var{file}.mi |
| Objective-C source code which should not be preprocessed. |
| |
| @item @var{file}.h |
| C or C++ header file to be turned into a precompiled header. |
| |
| @item @var{file}.cc |
| @itemx @var{file}.cp |
| @itemx @var{file}.cxx |
| @itemx @var{file}.cpp |
| @itemx @var{file}.CPP |
| @itemx @var{file}.c++ |
| @itemx @var{file}.C |
| C++ source code which must be preprocessed. Note that in @samp{.cxx}, |
| the last two letters must both be literally @samp{x}. Likewise, |
| @samp{.C} refers to a literal capital C@. |
| |
| @item @var{file}.hh |
| @itemx @var{file}.H |
| C++ header file to be turned into a precompiled header. |
| |
| @item @var{file}.f |
| @itemx @var{file}.for |
| @itemx @var{file}.FOR |
| Fortran source code which should not be preprocessed. |
| |
| @item @var{file}.F |
| @itemx @var{file}.fpp |
| @itemx @var{file}.FPP |
| Fortran source code which must be preprocessed (with the traditional |
| preprocessor). |
| |
| @item @var{file}.r |
| Fortran source code which must be preprocessed with a RATFOR |
| preprocessor (not included with GCC)@. |
| |
| @xref{Overall Options,,Options Controlling the Kind of Output, g77, |
| Using and Porting GNU Fortran}, for more details of the handling of |
| Fortran input files. |
| |
| @c FIXME: Descriptions of Java file types. |
| @c @var{file}.java |
| @c @var{file}.class |
| @c @var{file}.zip |
| @c @var{file}.jar |
| |
| @item @var{file}.ads |
| Ada source code file which contains a library unit declaration (a |
| declaration of a package, subprogram, or generic, or a generic |
| instantiation), or a library unit renaming declaration (a package, |
| generic, or subprogram renaming declaration). Such files are also |
| called @dfn{specs}. |
| |
| @itemx @var{file}.adb |
| Ada source code file containing a library unit body (a subprogram or |
| package body). Such files are also called @dfn{bodies}. |
| |
| @c GCC also knows about some suffixes for languages not yet included: |
| @c Pascal: |
| @c @var{file}.p |
| @c @var{file}.pas |
| |
| @item @var{file}.s |
| Assembler code. |
| |
| @item @var{file}.S |
| Assembler code which must be preprocessed. |
| |
| @item @var{other} |
| An object file to be fed straight into linking. |
| Any file name with no recognized suffix is treated this way. |
| @end table |
| |
| @opindex x |
| You can specify the input language explicitly with the @option{-x} option: |
| |
| @table @gcctabopt |
| @item -x @var{language} |
| Specify explicitly the @var{language} for the following input files |
| (rather than letting the compiler choose a default based on the file |
| name suffix). This option applies to all following input files until |
| the next @option{-x} option. Possible values for @var{language} are: |
| @smallexample |
| c c-header cpp-output |
| c++ c++-header c++-cpp-output |
| objective-c objective-c-header objc-cpp-output |
| assembler assembler-with-cpp |
| ada |
| f77 f77-cpp-input ratfor |
| java |
| treelang |
| @end smallexample |
| |
| @item -x none |
| Turn off any specification of a language, so that subsequent files are |
| handled according to their file name suffixes (as they are if @option{-x} |
| has not been used at all). |
| |
| @item -pass-exit-codes |
| @opindex pass-exit-codes |
| Normally the @command{gcc} program will exit with the code of 1 if any |
| phase of the compiler returns a non-success return code. If you specify |
| @option{-pass-exit-codes}, the @command{gcc} program will instead return with |
| numerically highest error produced by any phase that returned an error |
| indication. |
| @end table |
| |
| If you only want some of the stages of compilation, you can use |
| @option{-x} (or filename suffixes) to tell @command{gcc} where to start, and |
| one of the options @option{-c}, @option{-S}, or @option{-E} to say where |
| @command{gcc} is to stop. Note that some combinations (for example, |
| @samp{-x cpp-output -E}) instruct @command{gcc} to do nothing at all. |
| |
| @table @gcctabopt |
| @item -c |
| @opindex c |
| Compile or assemble the source files, but do not link. The linking |
| stage simply is not done. The ultimate output is in the form of an |
| object file for each source file. |
| |
| By default, the object file name for a source file is made by replacing |
| the suffix @samp{.c}, @samp{.i}, @samp{.s}, etc., with @samp{.o}. |
| |
| Unrecognized input files, not requiring compilation or assembly, are |
| ignored. |
| |
| @item -S |
| @opindex S |
| Stop after the stage of compilation proper; do not assemble. The output |
| is in the form of an assembler code file for each non-assembler input |
| file specified. |
| |
| By default, the assembler file name for a source file is made by |
| replacing the suffix @samp{.c}, @samp{.i}, etc., with @samp{.s}. |
| |
| Input files that don't require compilation are ignored. |
| |
| @item -E |
| @opindex E |
| Stop after the preprocessing stage; do not run the compiler proper. The |
| output is in the form of preprocessed source code, which is sent to the |
| standard output. |
| |
| Input files which don't require preprocessing are ignored. |
| |
| @cindex output file option |
| @item -o @var{file} |
| @opindex o |
| Place output in file @var{file}. This applies regardless to whatever |
| sort of output is being produced, whether it be an executable file, |
| an object file, an assembler file or preprocessed C code. |
| |
| If you specify @option{-o} when compiling more than one input file, or |
| you are producing an executable file as output, all the source files |
| on the command line will be compiled at once. |
| |
| If @option{-o} is not specified, the default is to put an executable file |
| in @file{a.out}, the object file for @file{@var{source}.@var{suffix}} in |
| @file{@var{source}.o}, its assembler file in @file{@var{source}.s}, and |
| all preprocessed C source on standard output. |
| |
| @item -v |
| @opindex v |
| Print (on standard error output) the commands executed to run the stages |
| of compilation. Also print the version number of the compiler driver |
| program and of the preprocessor and the compiler proper. |
| |
| @item -### |
| @opindex ### |
| Like @option{-v} except the commands are not executed and all command |
| arguments are quoted. This is useful for shell scripts to capture the |
| driver-generated command lines. |
| |
| @item -pipe |
| @opindex pipe |
| Use pipes rather than temporary files for communication between the |
| various stages of compilation. This fails to work on some systems where |
| the assembler is unable to read from a pipe; but the GNU assembler has |
| no trouble. |
| |
| @item --help |
| @opindex help |
| Print (on the standard output) a description of the command line options |
| understood by @command{gcc}. If the @option{-v} option is also specified |
| then @option{--help} will also be passed on to the various processes |
| invoked by @command{gcc}, so that they can display the command line options |
| they accept. If the @option{-Wextra} option is also specified then command |
| line options which have no documentation associated with them will also |
| be displayed. |
| |
| @item --target-help |
| @opindex target-help |
| Print (on the standard output) a description of target specific command |
| line options for each tool. |
| |
| @item --version |
| @opindex version |
| Display the version number and copyrights of the invoked GCC. |
| @end table |
| |
| @node Invoking G++ |
| @section Compiling C++ Programs |
| |
| @cindex suffixes for C++ source |
| @cindex C++ source file suffixes |
| C++ source files conventionally use one of the suffixes @samp{.C}, |
| @samp{.cc}, @samp{.cpp}, @samp{.CPP}, @samp{.c++}, @samp{.cp}, or |
| @samp{.cxx}; C++ header files often use @samp{.hh} or @samp{.H}; and |
| preprocessed C++ files use the suffix @samp{.ii}. GCC recognizes |
| files with these names and compiles them as C++ programs even if you |
| call the compiler the same way as for compiling C programs (usually |
| with the name @command{gcc}). |
| |
| @findex g++ |
| @findex c++ |
| However, C++ programs often require class libraries as well as a |
| compiler that understands the C++ language---and under some |
| circumstances, you might want to compile programs or header files from |
| standard input, or otherwise without a suffix that flags them as C++ |
| programs. You might also like to precompile a C header file with a |
| @samp{.h} extension to be used in C++ compilations. @command{g++} is a |
| program that calls GCC with the default language set to C++, and |
| automatically specifies linking against the C++ library. On many |
| systems, @command{g++} is also installed with the name @command{c++}. |
| |
| @cindex invoking @command{g++} |
| When you compile C++ programs, you may specify many of the same |
| command-line options that you use for compiling programs in any |
| language; or command-line options meaningful for C and related |
| languages; or options that are meaningful only for C++ programs. |
| @xref{C Dialect Options,,Options Controlling C Dialect}, for |
| explanations of options for languages related to C@. |
| @xref{C++ Dialect Options,,Options Controlling C++ Dialect}, for |
| explanations of options that are meaningful only for C++ programs. |
| |
| @node C Dialect Options |
| @section Options Controlling C Dialect |
| @cindex dialect options |
| @cindex language dialect options |
| @cindex options, dialect |
| |
| The following options control the dialect of C (or languages derived |
| from C, such as C++ and Objective-C) that the compiler accepts: |
| |
| @table @gcctabopt |
| @cindex ANSI support |
| @cindex ISO support |
| @item -ansi |
| @opindex ansi |
| In C mode, support all ISO C90 programs. In C++ mode, |
| remove GNU extensions that conflict with ISO C++. |
| |
| This turns off certain features of GCC that are incompatible with ISO |
| C90 (when compiling C code), or of standard C++ (when compiling C++ code), |
| such as the @code{asm} and @code{typeof} keywords, and |
| predefined macros such as @code{unix} and @code{vax} that identify the |
| type of system you are using. It also enables the undesirable and |
| rarely used ISO trigraph feature. For the C compiler, |
| it disables recognition of C++ style @samp{//} comments as well as |
| the @code{inline} keyword. |
| |
| The alternate keywords @code{__asm__}, @code{__extension__}, |
| @code{__inline__} and @code{__typeof__} continue to work despite |
| @option{-ansi}. You would not want to use them in an ISO C program, of |
| course, but it is useful to put them in header files that might be included |
| in compilations done with @option{-ansi}. Alternate predefined macros |
| such as @code{__unix__} and @code{__vax__} are also available, with or |
| without @option{-ansi}. |
| |
| The @option{-ansi} option does not cause non-ISO programs to be |
| rejected gratuitously. For that, @option{-pedantic} is required in |
| addition to @option{-ansi}. @xref{Warning Options}. |
| |
| The macro @code{__STRICT_ANSI__} is predefined when the @option{-ansi} |
| option is used. Some header files may notice this macro and refrain |
| from declaring certain functions or defining certain macros that the |
| ISO standard doesn't call for; this is to avoid interfering with any |
| programs that might use these names for other things. |
| |
| Functions which would normally be built in but do not have semantics |
| defined by ISO C (such as @code{alloca} and @code{ffs}) are not built-in |
| functions with @option{-ansi} is used. @xref{Other Builtins,,Other |
| built-in functions provided by GCC}, for details of the functions |
| affected. |
| |
| @item -std= |
| @opindex std |
| Determine the language standard. This option is currently only |
| supported when compiling C or C++. A value for this option must be |
| provided; possible values are |
| |
| @table @samp |
| @item c89 |
| @itemx iso9899:1990 |
| ISO C90 (same as @option{-ansi}). |
| |
| @item iso9899:199409 |
| ISO C90 as modified in amendment 1. |
| |
| @item c99 |
| @itemx c9x |
| @itemx iso9899:1999 |
| @itemx iso9899:199x |
| ISO C99. Note that this standard is not yet fully supported; see |
| @w{@uref{http://gcc.gnu.org/gcc-3.4/c99status.html}} for more information. The |
| names @samp{c9x} and @samp{iso9899:199x} are deprecated. |
| |
| @item gnu89 |
| Default, ISO C90 plus GNU extensions (including some C99 features). |
| |
| @item gnu99 |
| @itemx gnu9x |
| ISO C99 plus GNU extensions. When ISO C99 is fully implemented in GCC, |
| this will become the default. The name @samp{gnu9x} is deprecated. |
| |
| @item c++98 |
| The 1998 ISO C++ standard plus amendments. |
| |
| @item gnu++98 |
| The same as @option{-std=c++98} plus GNU extensions. This is the |
| default for C++ code. |
| @end table |
| |
| Even when this option is not specified, you can still use some of the |
| features of newer standards in so far as they do not conflict with |
| previous C standards. For example, you may use @code{__restrict__} even |
| when @option{-std=c99} is not specified. |
| |
| The @option{-std} options specifying some version of ISO C have the same |
| effects as @option{-ansi}, except that features that were not in ISO C90 |
| but are in the specified version (for example, @samp{//} comments and |
| the @code{inline} keyword in ISO C99) are not disabled. |
| |
| @xref{Standards,,Language Standards Supported by GCC}, for details of |
| these standard versions. |
| |
| @item -aux-info @var{filename} |
| @opindex aux-info |
| Output to the given filename prototyped declarations for all functions |
| declared and/or defined in a translation unit, including those in header |
| files. This option is silently ignored in any language other than C@. |
| |
| Besides declarations, the file indicates, in comments, the origin of |
| each declaration (source file and line), whether the declaration was |
| implicit, prototyped or unprototyped (@samp{I}, @samp{N} for new or |
| @samp{O} for old, respectively, in the first character after the line |
| number and the colon), and whether it came from a declaration or a |
| definition (@samp{C} or @samp{F}, respectively, in the following |
| character). In the case of function definitions, a K&R-style list of |
| arguments followed by their declarations is also provided, inside |
| comments, after the declaration. |
| |
| @item -fno-asm |
| @opindex fno-asm |
| Do not recognize @code{asm}, @code{inline} or @code{typeof} as a |
| keyword, so that code can use these words as identifiers. You can use |
| the keywords @code{__asm__}, @code{__inline__} and @code{__typeof__} |
| instead. @option{-ansi} implies @option{-fno-asm}. |
| |
| In C++, this switch only affects the @code{typeof} keyword, since |
| @code{asm} and @code{inline} are standard keywords. You may want to |
| use the @option{-fno-gnu-keywords} flag instead, which has the same |
| effect. In C99 mode (@option{-std=c99} or @option{-std=gnu99}), this |
| switch only affects the @code{asm} and @code{typeof} keywords, since |
| @code{inline} is a standard keyword in ISO C99. |
| |
| @item -fno-builtin |
| @itemx -fno-builtin-@var{function} |
| @opindex fno-builtin |
| @cindex built-in functions |
| Don't recognize built-in functions that do not begin with |
| @samp{__builtin_} as prefix. @xref{Other Builtins,,Other built-in |
| functions provided by GCC}, for details of the functions affected, |
| including those which are not built-in functions when @option{-ansi} or |
| @option{-std} options for strict ISO C conformance are used because they |
| do not have an ISO standard meaning. |
| |
| GCC normally generates special code to handle certain built-in functions |
| more efficiently; for instance, calls to @code{alloca} may become single |
| instructions that adjust the stack directly, and calls to @code{memcpy} |
| may become inline copy loops. The resulting code is often both smaller |
| and faster, but since the function calls no longer appear as such, you |
| cannot set a breakpoint on those calls, nor can you change the behavior |
| of the functions by linking with a different library. |
| |
| With the @option{-fno-builtin-@var{function}} option |
| only the built-in function @var{function} is |
| disabled. @var{function} must not begin with @samp{__builtin_}. If a |
| function is named this is not built-in in this version of GCC, this |
| option is ignored. There is no corresponding |
| @option{-fbuiltin-@var{function}} option; if you wish to enable |
| built-in functions selectively when using @option{-fno-builtin} or |
| @option{-ffreestanding}, you may define macros such as: |
| |
| @smallexample |
| #define abs(n) __builtin_abs ((n)) |
| #define strcpy(d, s) __builtin_strcpy ((d), (s)) |
| @end smallexample |
| |
| @item -fhosted |
| @opindex fhosted |
| @cindex hosted environment |
| |
| Assert that compilation takes place in a hosted environment. This implies |
| @option{-fbuiltin}. A hosted environment is one in which the |
| entire standard library is available, and in which @code{main} has a return |
| type of @code{int}. Examples are nearly everything except a kernel. |
| This is equivalent to @option{-fno-freestanding}. |
| |
| @item -ffreestanding |
| @opindex ffreestanding |
| @cindex hosted environment |
| |
| Assert that compilation takes place in a freestanding environment. This |
| implies @option{-fno-builtin}. A freestanding environment |
| is one in which the standard library may not exist, and program startup may |
| not necessarily be at @code{main}. The most obvious example is an OS kernel. |
| This is equivalent to @option{-fno-hosted}. |
| |
| @xref{Standards,,Language Standards Supported by GCC}, for details of |
| freestanding and hosted environments. |
| |
| @item -fms-extensions |
| @opindex fms-extensions |
| Accept some non-standard constructs used in Microsoft header files. |
| |
| @item -trigraphs |
| @opindex trigraphs |
| Support ISO C trigraphs. The @option{-ansi} option (and @option{-std} |
| options for strict ISO C conformance) implies @option{-trigraphs}. |
| |
| @item -no-integrated-cpp |
| @opindex no-integrated-cpp |
| Performs a compilation in two passes: preprocessing and compiling. This |
| option allows a user supplied "cc1", "cc1plus", or "cc1obj" via the |
| @option{-B} option. The user supplied compilation step can then add in |
| an additional preprocessing step after normal preprocessing but before |
| compiling. The default is to use the integrated cpp (internal cpp) |
| |
| The semantics of this option will change if "cc1", "cc1plus", and |
| "cc1obj" are merged. |
| |
| @cindex traditional C language |
| @cindex C language, traditional |
| @item -traditional |
| @itemx -traditional-cpp |
| @opindex traditional-cpp |
| @opindex traditional |
| Formerly, these options caused GCC to attempt to emulate a pre-standard |
| C compiler. They are now only supported with the @option{-E} switch. |
| The preprocessor continues to support a pre-standard mode. See the GNU |
| CPP manual for details. |
| |
| @item -fcond-mismatch |
| @opindex fcond-mismatch |
| Allow conditional expressions with mismatched types in the second and |
| third arguments. The value of such an expression is void. This option |
| is not supported for C++. |
| |
| @item -funsigned-char |
| @opindex funsigned-char |
| Let the type @code{char} be unsigned, like @code{unsigned char}. |
| |
| Each kind of machine has a default for what @code{char} should |
| be. It is either like @code{unsigned char} by default or like |
| @code{signed char} by default. |
| |
| Ideally, a portable program should always use @code{signed char} or |
| @code{unsigned char} when it depends on the signedness of an object. |
| But many programs have been written to use plain @code{char} and |
| expect it to be signed, or expect it to be unsigned, depending on the |
| machines they were written for. This option, and its inverse, let you |
| make such a program work with the opposite default. |
| |
| The type @code{char} is always a distinct type from each of |
| @code{signed char} or @code{unsigned char}, even though its behavior |
| is always just like one of those two. |
| |
| @item -fsigned-char |
| @opindex fsigned-char |
| Let the type @code{char} be signed, like @code{signed char}. |
| |
| Note that this is equivalent to @option{-fno-unsigned-char}, which is |
| the negative form of @option{-funsigned-char}. Likewise, the option |
| @option{-fno-signed-char} is equivalent to @option{-funsigned-char}. |
| |
| @item -fsigned-bitfields |
| @itemx -funsigned-bitfields |
| @itemx -fno-signed-bitfields |
| @itemx -fno-unsigned-bitfields |
| @opindex fsigned-bitfields |
| @opindex funsigned-bitfields |
| @opindex fno-signed-bitfields |
| @opindex fno-unsigned-bitfields |
| These options control whether a bit-field is signed or unsigned, when the |
| declaration does not use either @code{signed} or @code{unsigned}. By |
| default, such a bit-field is signed, because this is consistent: the |
| basic integer types such as @code{int} are signed types. |
| |
| @item -fwritable-strings |
| @opindex fwritable-strings |
| Store string constants in the writable data segment and don't uniquize |
| them. This is for compatibility with old programs which assume they can |
| write into string constants. |
| |
| Writing into string constants is a very bad idea; ``constants'' should |
| be constant. |
| |
| This option is deprecated. |
| @end table |
| |
| @node C++ Dialect Options |
| @section Options Controlling C++ Dialect |
| |
| @cindex compiler options, C++ |
| @cindex C++ options, command line |
| @cindex options, C++ |
| This section describes the command-line options that are only meaningful |
| for C++ programs; but you can also use most of the GNU compiler options |
| regardless of what language your program is in. For example, you |
| might compile a file @code{firstClass.C} like this: |
| |
| @smallexample |
| g++ -g -frepo -O -c firstClass.C |
| @end smallexample |
| |
| @noindent |
| In this example, only @option{-frepo} is an option meant |
| only for C++ programs; you can use the other options with any |
| language supported by GCC@. |
| |
| Here is a list of options that are @emph{only} for compiling C++ programs: |
| |
| @table @gcctabopt |
| |
| @item -fabi-version=@var{n} |
| @opindex fabi-version |
| Use version @var{n} of the C++ ABI. Version 2 is the version of the |
| C++ ABI that first appeared in G++ 3.4. Version 1 is the version of |
| the C++ ABI that first appeared in G++ 3.2. Version 0 will always be |
| the version that conforms most closely to the C++ ABI specification. |
| Therefore, the ABI obtained using version 0 will change as ABI bugs |
| are fixed. |
| |
| The default is version 2. |
| |
| @item -fno-access-control |
| @opindex fno-access-control |
| Turn off all access checking. This switch is mainly useful for working |
| around bugs in the access control code. |
| |
| @item -fcheck-new |
| @opindex fcheck-new |
| Check that the pointer returned by @code{operator new} is non-null |
| before attempting to modify the storage allocated. This check is |
| normally unnecessary because the C++ standard specifies that |
| @code{operator new} will only return @code{0} if it is declared |
| @samp{throw()}, in which case the compiler will always check the |
| return value even without this option. In all other cases, when |
| @code{operator new} has a non-empty exception specification, memory |
| exhaustion is signalled by throwing @code{std::bad_alloc}. See also |
| @samp{new (nothrow)}. |
| |
| @item -fconserve-space |
| @opindex fconserve-space |
| Put uninitialized or runtime-initialized global variables into the |
| common segment, as C does. This saves space in the executable at the |
| cost of not diagnosing duplicate definitions. If you compile with this |
| flag and your program mysteriously crashes after @code{main()} has |
| completed, you may have an object that is being destroyed twice because |
| two definitions were merged. |
| |
| This option is no longer useful on most targets, now that support has |
| been added for putting variables into BSS without making them common. |
| |
| @item -fno-const-strings |
| @opindex fno-const-strings |
| Give string constants type @code{char *} instead of type @code{const |
| char *}. By default, G++ uses type @code{const char *} as required by |
| the standard. Even if you use @option{-fno-const-strings}, you cannot |
| actually modify the value of a string constant, unless you also use |
| @option{-fwritable-strings}. |
| |
| This option might be removed in a future release of G++. For maximum |
| portability, you should structure your code so that it works with |
| string constants that have type @code{const char *}. |
| |
| @item -fno-elide-constructors |
| @opindex fno-elide-constructors |
| The C++ standard allows an implementation to omit creating a temporary |
| which is only used to initialize another object of the same type. |
| Specifying this option disables that optimization, and forces G++ to |
| call the copy constructor in all cases. |
| |
| @item -fno-enforce-eh-specs |
| @opindex fno-enforce-eh-specs |
| Don't check for violation of exception specifications at runtime. This |
| option violates the C++ standard, but may be useful for reducing code |
| size in production builds, much like defining @samp{NDEBUG}. The compiler |
| will still optimize based on the exception specifications. |
| |
| @item -ffor-scope |
| @itemx -fno-for-scope |
| @opindex ffor-scope |
| @opindex fno-for-scope |
| If @option{-ffor-scope} is specified, the scope of variables declared in |
| a @i{for-init-statement} is limited to the @samp{for} loop itself, |
| as specified by the C++ standard. |
| If @option{-fno-for-scope} is specified, the scope of variables declared in |
| a @i{for-init-statement} extends to the end of the enclosing scope, |
| as was the case in old versions of G++, and other (traditional) |
| implementations of C++. |
| |
| The default if neither flag is given to follow the standard, |
| but to allow and give a warning for old-style code that would |
| otherwise be invalid, or have different behavior. |
| |
| @item -fno-gnu-keywords |
| @opindex fno-gnu-keywords |
| Do not recognize @code{typeof} as a keyword, so that code can use this |
| word as an identifier. You can use the keyword @code{__typeof__} instead. |
| @option{-ansi} implies @option{-fno-gnu-keywords}. |
| |
| @item -fno-implicit-templates |
| @opindex fno-implicit-templates |
| Never emit code for non-inline templates which are instantiated |
| implicitly (i.e.@: by use); only emit code for explicit instantiations. |
| @xref{Template Instantiation}, for more information. |
| |
| @item -fno-implicit-inline-templates |
| @opindex fno-implicit-inline-templates |
| Don't emit code for implicit instantiations of inline templates, either. |
| The default is to handle inlines differently so that compiles with and |
| without optimization will need the same set of explicit instantiations. |
| |
| @item -fno-implement-inlines |
| @opindex fno-implement-inlines |
| To save space, do not emit out-of-line copies of inline functions |
| controlled by @samp{#pragma implementation}. This will cause linker |
| errors if these functions are not inlined everywhere they are called. |
| |
| @item -fms-extensions |
| @opindex fms-extensions |
| Disable pedantic warnings about constructs used in MFC, such as implicit |
| int and getting a pointer to member function via non-standard syntax. |
| |
| @item -fno-nonansi-builtins |
| @opindex fno-nonansi-builtins |
| Disable built-in declarations of functions that are not mandated by |
| ANSI/ISO C@. These include @code{ffs}, @code{alloca}, @code{_exit}, |
| @code{index}, @code{bzero}, @code{conjf}, and other related functions. |
| |
| @item -fno-operator-names |
| @opindex fno-operator-names |
| Do not treat the operator name keywords @code{and}, @code{bitand}, |
| @code{bitor}, @code{compl}, @code{not}, @code{or} and @code{xor} as |
| synonyms as keywords. |
| |
| @item -fno-optional-diags |
| @opindex fno-optional-diags |
| Disable diagnostics that the standard says a compiler does not need to |
| issue. Currently, the only such diagnostic issued by G++ is the one for |
| a name having multiple meanings within a class. |
| |
| @item -fpermissive |
| @opindex fpermissive |
| Downgrade some diagnostics about nonconformant code from errors to |
| warnings. Thus, using @option{-fpermissive} will allow some |
| nonconforming code to compile. |
| |
| @item -frepo |
| @opindex frepo |
| Enable automatic template instantiation at link time. This option also |
| implies @option{-fno-implicit-templates}. @xref{Template |
| Instantiation}, for more information. |
| |
| @item -fno-rtti |
| @opindex fno-rtti |
| Disable generation of information about every class with virtual |
| functions for use by the C++ runtime type identification features |
| (@samp{dynamic_cast} and @samp{typeid}). If you don't use those parts |
| of the language, you can save some space by using this flag. Note that |
| exception handling uses the same information, but it will generate it as |
| needed. |
| |
| @item -fstats |
| @opindex fstats |
| Emit statistics about front-end processing at the end of the compilation. |
| This information is generally only useful to the G++ development team. |
| |
| @item -ftemplate-depth-@var{n} |
| @opindex ftemplate-depth |
| Set the maximum instantiation depth for template classes to @var{n}. |
| A limit on the template instantiation depth is needed to detect |
| endless recursions during template class instantiation. ANSI/ISO C++ |
| conforming programs must not rely on a maximum depth greater than 17. |
| |
| @item -fuse-cxa-atexit |
| @opindex fuse-cxa-atexit |
| Register destructors for objects with static storage duration with the |
| @code{__cxa_atexit} function rather than the @code{atexit} function. |
| This option is required for fully standards-compliant handling of static |
| destructors, but will only work if your C library supports |
| @code{__cxa_atexit}. |
| |
| @item -fno-weak |
| @opindex fno-weak |
| Do not use weak symbol support, even if it is provided by the linker. |
| By default, G++ will use weak symbols if they are available. This |
| option exists only for testing, and should not be used by end-users; |
| it will result in inferior code and has no benefits. This option may |
| be removed in a future release of G++. |
| |
| @item -nostdinc++ |
| @opindex nostdinc++ |
| Do not search for header files in the standard directories specific to |
| C++, but do still search the other standard directories. (This option |
| is used when building the C++ library.) |
| @end table |
| |
| In addition, these optimization, warning, and code generation options |
| have meanings only for C++ programs: |
| |
| @table @gcctabopt |
| @item -fno-default-inline |
| @opindex fno-default-inline |
| Do not assume @samp{inline} for functions defined inside a class scope. |
| @xref{Optimize Options,,Options That Control Optimization}. Note that these |
| functions will have linkage like inline functions; they just won't be |
| inlined by default. |
| |
| @item -Wabi @r{(C++ only)} |
| @opindex Wabi |
| Warn when G++ generates code that is probably not compatible with the |
| vendor-neutral C++ ABI. Although an effort has been made to warn about |
| all such cases, there are probably some cases that are not warned about, |
| even though G++ is generating incompatible code. There may also be |
| cases where warnings are emitted even though the code that is generated |
| will be compatible. |
| |
| You should rewrite your code to avoid these warnings if you are |
| concerned about the fact that code generated by G++ may not be binary |
| compatible with code generated by other compilers. |
| |
| The known incompatibilities at this point include: |
| |
| @itemize @bullet |
| |
| @item |
| Incorrect handling of tail-padding for bit-fields. G++ may attempt to |
| pack data into the same byte as a base class. For example: |
| |
| @smallexample |
| struct A @{ virtual void f(); int f1 : 1; @}; |
| struct B : public A @{ int f2 : 1; @}; |
| @end smallexample |
| |
| @noindent |
| In this case, G++ will place @code{B::f2} into the same byte |
| as@code{A::f1}; other compilers will not. You can avoid this problem |
| by explicitly padding @code{A} so that its size is a multiple of the |
| byte size on your platform; that will cause G++ and other compilers to |
| layout @code{B} identically. |
| |
| @item |
| Incorrect handling of tail-padding for virtual bases. G++ does not use |
| tail padding when laying out virtual bases. For example: |
| |
| @smallexample |
| struct A @{ virtual void f(); char c1; @}; |
| struct B @{ B(); char c2; @}; |
| struct C : public A, public virtual B @{@}; |
| @end smallexample |
| |
| @noindent |
| In this case, G++ will not place @code{B} into the tail-padding for |
| @code{A}; other compilers will. You can avoid this problem by |
| explicitly padding @code{A} so that its size is a multiple of its |
| alignment (ignoring virtual base classes); that will cause G++ and other |
| compilers to layout @code{C} identically. |
| |
| @item |
| Incorrect handling of bit-fields with declared widths greater than that |
| of their underlying types, when the bit-fields appear in a union. For |
| example: |
| |
| @smallexample |
| union U @{ int i : 4096; @}; |
| @end smallexample |
| |
| @noindent |
| Assuming that an @code{int} does not have 4096 bits, G++ will make the |
| union too small by the number of bits in an @code{int}. |
| |
| @item |
| Empty classes can be placed at incorrect offsets. For example: |
| |
| @smallexample |
| struct A @{@}; |
| |
| struct B @{ |
| A a; |
| virtual void f (); |
| @}; |
| |
| struct C : public B, public A @{@}; |
| @end smallexample |
| |
| @noindent |
| G++ will place the @code{A} base class of @code{C} at a nonzero offset; |
| it should be placed at offset zero. G++ mistakenly believes that the |
| @code{A} data member of @code{B} is already at offset zero. |
| |
| @item |
| Names of template functions whose types involve @code{typename} or |
| template template parameters can be mangled incorrectly. |
| |
| @smallexample |
| template <typename Q> |
| void f(typename Q::X) @{@} |
| |
| template <template <typename> class Q> |
| void f(typename Q<int>::X) @{@} |
| @end smallexample |
| |
| @noindent |
| Instantiations of these templates may be mangled incorrectly. |
| |
| @end itemize |
| |
| @item -Wctor-dtor-privacy @r{(C++ only)} |
| @opindex Wctor-dtor-privacy |
| Warn when a class seems unusable because all the constructors or |
| destructors in that class are private, and it has neither friends nor |
| public static member functions. |
| |
| @item -Wnon-virtual-dtor @r{(C++ only)} |
| @opindex Wnon-virtual-dtor |
| Warn when a class appears to be polymorphic, thereby requiring a virtual |
| destructor, yet it declares a non-virtual one. |
| This warning is enabled by @option{-Wall}. |
| |
| @item -Wreorder @r{(C++ only)} |
| @opindex Wreorder |
| @cindex reordering, warning |
| @cindex warning for reordering of member initializers |
| Warn when the order of member initializers given in the code does not |
| match the order in which they must be executed. For instance: |
| |
| @smallexample |
| struct A @{ |
| int i; |
| int j; |
| A(): j (0), i (1) @{ @} |
| @}; |
| @end smallexample |
| |
| The compiler will rearrange the member initializers for @samp{i} |
| and @samp{j} to match the declaration order of the members, emitting |
| a warning to that effect. This warning is enabled by @option{-Wall}. |
| @end table |
| |
| The following @option{-W@dots{}} options are not affected by @option{-Wall}. |
| |
| @table @gcctabopt |
| @item -Weffc++ @r{(C++ only)} |
| @opindex Weffc++ |
| Warn about violations of the following style guidelines from Scott Meyers' |
| @cite{Effective C++} book: |
| |
| @itemize @bullet |
| @item |
| Item 11: Define a copy constructor and an assignment operator for classes |
| with dynamically allocated memory. |
| |
| @item |
| Item 12: Prefer initialization to assignment in constructors. |
| |
| @item |
| Item 14: Make destructors virtual in base classes. |
| |
| @item |
| Item 15: Have @code{operator=} return a reference to @code{*this}. |
| |
| @item |
| Item 23: Don't try to return a reference when you must return an object. |
| |
| @end itemize |
| |
| Also warn about violations of the following style guidelines from |
| Scott Meyers' @cite{More Effective C++} book: |
| |
| @itemize @bullet |
| @item |
| Item 6: Distinguish between prefix and postfix forms of increment and |
| decrement operators. |
| |
| @item |
| Item 7: Never overload @code{&&}, @code{||}, or @code{,}. |
| |
| @end itemize |
| |
| When selecting this option, be aware that the standard library |
| headers do not obey all of these guidelines; use @samp{grep -v} |
| to filter out those warnings. |
| |
| @item -Wno-deprecated @r{(C++ only)} |
| @opindex Wno-deprecated |
| Do not warn about usage of deprecated features. @xref{Deprecated Features}. |
| |
| @item -Wno-non-template-friend @r{(C++ only)} |
| @opindex Wno-non-template-friend |
| Disable warnings when non-templatized friend functions are declared |
| within a template. Since the advent of explicit template specification |
| support in G++, if the name of the friend is an unqualified-id (i.e., |
| @samp{friend foo(int)}), the C++ language specification demands that the |
| friend declare or define an ordinary, nontemplate function. (Section |
| 14.5.3). Before G++ implemented explicit specification, unqualified-ids |
| could be interpreted as a particular specialization of a templatized |
| function. Because this non-conforming behavior is no longer the default |
| behavior for G++, @option{-Wnon-template-friend} allows the compiler to |
| check existing code for potential trouble spots and is on by default. |
| This new compiler behavior can be turned off with |
| @option{-Wno-non-template-friend} which keeps the conformant compiler code |
| but disables the helpful warning. |
| |
| @item -Wold-style-cast @r{(C++ only)} |
| @opindex Wold-style-cast |
| Warn if an old-style (C-style) cast to a non-void type is used within |
| a C++ program. The new-style casts (@samp{static_cast}, |
| @samp{reinterpret_cast}, and @samp{const_cast}) are less vulnerable to |
| unintended effects and much easier to search for. |
| |
| @item -Woverloaded-virtual @r{(C++ only)} |
| @opindex Woverloaded-virtual |
| @cindex overloaded virtual fn, warning |
| @cindex warning for overloaded virtual fn |
| Warn when a function declaration hides virtual functions from a |
| base class. For example, in: |
| |
| @smallexample |
| struct A @{ |
| virtual void f(); |
| @}; |
| |
| struct B: public A @{ |
| void f(int); |
| @}; |
| @end smallexample |
| |
| the @code{A} class version of @code{f} is hidden in @code{B}, and code |
| like: |
| |
| @smallexample |
| B* b; |
| b->f(); |
| @end smallexample |
| |
| will fail to compile. |
| |
| @item -Wno-pmf-conversions @r{(C++ only)} |
| @opindex Wno-pmf-conversions |
| Disable the diagnostic for converting a bound pointer to member function |
| to a plain pointer. |
| |
| @item -Wsign-promo @r{(C++ only)} |
| @opindex Wsign-promo |
| Warn when overload resolution chooses a promotion from unsigned or |
| enumerated type to a signed type, over a conversion to an unsigned type of |
| the same size. Previous versions of G++ would try to preserve |
| unsignedness, but the standard mandates the current behavior. |
| |
| @item -Wsynth @r{(C++ only)} |
| @opindex Wsynth |
| @cindex warning for synthesized methods |
| @cindex synthesized methods, warning |
| Warn when G++'s synthesis behavior does not match that of cfront. For |
| instance: |
| |
| @smallexample |
| struct A @{ |
| operator int (); |
| A& operator = (int); |
| @}; |
| |
| main () |
| @{ |
| A a,b; |
| a = b; |
| @} |
| @end smallexample |
| |
| In this example, G++ will synthesize a default @samp{A& operator = |
| (const A&);}, while cfront will use the user-defined @samp{operator =}. |
| @end table |
| |
| @node Objective-C Dialect Options |
| @section Options Controlling Objective-C Dialect |
| |
| @cindex compiler options, Objective-C |
| @cindex Objective-C options, command line |
| @cindex options, Objective-C |
| (NOTE: This manual does not describe the Objective-C language itself. See |
| @w{@uref{http://gcc.gnu.org/readings.html}} for references.) |
| |
| This section describes the command-line options that are only meaningful |
| for Objective-C programs, but you can also use most of the GNU compiler |
| options regardless of what language your program is in. For example, |
| you might compile a file @code{some_class.m} like this: |
| |
| @smallexample |
| gcc -g -fgnu-runtime -O -c some_class.m |
| @end smallexample |
| |
| @noindent |
| In this example, @option{-fgnu-runtime} is an option meant only for |
| Objective-C programs; you can use the other options with any language |
| supported by GCC@. |
| |
| Here is a list of options that are @emph{only} for compiling Objective-C |
| programs: |
| |
| @table @gcctabopt |
| @item -fconstant-string-class=@var{class-name} |
| @opindex fconstant-string-class |
| Use @var{class-name} as the name of the class to instantiate for each |
| literal string specified with the syntax @code{@@"@dots{}"}. The default |
| class name is @code{NXConstantString} if the GNU runtime is being used, and |
| @code{NSConstantString} if the NeXT runtime is being used (see below). The |
| @option{-fconstant-cfstrings} option, if also present, will override the |
| @option{-fconstant-string-class} setting and cause @code{@@"@dots{}"} literals |
| to be laid out as constant CoreFoundation strings. |
| |
| @item -fgnu-runtime |
| @opindex fgnu-runtime |
| Generate object code compatible with the standard GNU Objective-C |
| runtime. This is the default for most types of systems. |
| |
| @item -fnext-runtime |
| @opindex fnext-runtime |
| Generate output compatible with the NeXT runtime. This is the default |
| for NeXT-based systems, including Darwin and Mac OS X@. The macro |
| @code{__NEXT_RUNTIME__} is predefined if (and only if) this option is |
| used. |
| |
| @item -fno-nil-receivers |
| @opindex fno-nil-receivers |
| Assume that all Objective-C message dispatches (e.g., |
| @code{[receiver message:arg]}) in this translation unit ensure that the receiver |
| is not @code{nil}. This allows for more efficient entry points in the runtime to be |
| used. Currently, this option is only available in conjunction with |
| the NeXT runtime on Mac OS X 10.3 and later. |
| |
| @item -fobjc-exceptions |
| @opindex fobjc-exceptions |
| Enable syntactic support for structured exception handling in Objective-C, |
| similar to what is offered by C++ and Java. Currently, this option is only |
| available in conjunction with the NeXT runtime on Mac OS X 10.3 and later. |
| |
| @smallexample |
| @@try @{ |
| @dots{} |
| @@throw expr; |
| @dots{} |
| @} |
| @@catch (AnObjCClass *exc) @{ |
| @dots{} |
| @@throw expr; |
| @dots{} |
| @@throw; |
| @dots{} |
| @} |
| @@catch (AnotherClass *exc) @{ |
| @dots{} |
| @} |
| @@catch (id allOthers) @{ |
| @dots{} |
| @} |
| @@finally @{ |
| @dots{} |
| @@throw expr; |
| @dots{} |
| @} |
| @end smallexample |
| |
| The @code{@@throw} statement may appear anywhere in an Objective-C or |
| Objective-C++ program; when used inside of a @code{@@catch} block, the |
| @code{@@throw} may appear without an argument (as shown above), in which case |
| the object caught by the @code{@@catch} will be rethrown. |
| |
| Note that only (pointers to) Objective-C objects may be thrown and |
| caught using this scheme. When an object is thrown, it will be caught |
| by the nearest @code{@@catch} clause capable of handling objects of that type, |
| analogously to how @code{catch} blocks work in C++ and Java. A |
| @code{@@catch(id @dots{})} clause (as shown above) may also be provided to catch |
| any and all Objective-C exceptions not caught by previous @code{@@catch} |
| clauses (if any). |
| |
| The @code{@@finally} clause, if present, will be executed upon exit from the |
| immediately preceding @code{@@try @dots{} @@catch} section. This will happen |
| regardless of whether any exceptions are thrown, caught or rethrown |
| inside the @code{@@try @dots{} @@catch} section, analogously to the behavior |
| of the @code{finally} clause in Java. |
| |
| There are several caveats to using the new exception mechanism: |
| |
| @itemize @bullet |
| @item |
| Although currently designed to be binary compatible with @code{NS_HANDLER}-style |
| idioms provided by the @code{NSException} class, the new |
| exceptions can only be used on Mac OS X 10.3 (Panther) and later |
| systems, due to additional functionality needed in the (NeXT) Objective-C |
| runtime. |
| |
| @item |
| As mentioned above, the new exceptions do not support handling |
| types other than Objective-C objects. Furthermore, when used from |
| Objective-C++, the Objective-C exception model does not interoperate with C++ |
| exceptions at this time. This means you cannot @code{@@throw} an exception |
| from Objective-C and @code{catch} it in C++, or vice versa |
| (i.e., @code{throw @dots{} @@catch}). |
| @end itemize |
| |
| The @option{-fobjc-exceptions} switch also enables the use of synchronization |
| blocks for thread-safe execution: |
| |
| @smallexample |
| @@synchronized (ObjCClass *guard) @{ |
| @dots{} |
| @} |
| @end smallexample |
| |
| Upon entering the @code{@@synchronized} block, a thread of execution shall |
| first check whether a lock has been placed on the corresponding @code{guard} |
| object by another thread. If it has, the current thread shall wait until |
| the other thread relinquishes its lock. Once @code{guard} becomes available, |
| the current thread will place its own lock on it, execute the code contained in |
| the @code{@@synchronized} block, and finally relinquish the lock (thereby |
| making @code{guard} available to other threads). |
| |
| Unlike Java, Objective-C does not allow for entire methods to be marked |
| @code{@@synchronized}. Note that throwing exceptions out of |
| @code{@@synchronized} blocks is allowed, and will cause the guarding object |
| to be unlocked properly. |
| |
| @item -freplace-objc-classes |
| @opindex freplace-objc-classes |
| Emit a special marker instructing @command{ld(1)} not to statically link in |
| the resulting object file, and allow @command{dyld(1)} to load it in at |
| run time instead. This is used in conjunction with the Fix-and-Continue |
| debugging mode, where the object file in question may be recompiled and |
| dynamically reloaded in the course of program execution, without the need |
| to restart the program itself. Currently, Fix-and-Continue functionality |
| is only available in conjunction with the NeXT runtime on Mac OS X 10.3 |
| and later. |
| |
| @item -fzero-link |
| @opindex fzero-link |
| When compiling for the NeXT runtime, the compiler ordinarily replaces calls |
| to @code{objc_getClass("@dots{}")} (when the name of the class is known at |
| compile time) with static class references that get initialized at load time, |
| which improves run-time performance. Specifying the @option{-fzero-link} flag |
| suppresses this behavior and causes calls to @code{objc_getClass("@dots{}")} |
| to be retained. This is useful in Zero-Link debugging mode, since it allows |
| for individual class implementations to be modified during program execution. |
| |
| @item -gen-decls |
| @opindex gen-decls |
| Dump interface declarations for all classes seen in the source file to a |
| file named @file{@var{sourcename}.decl}. |
| |
| @item -Wno-protocol |
| @opindex Wno-protocol |
| If a class is declared to implement a protocol, a warning is issued for |
| every method in the protocol that is not implemented by the class. The |
| default behavior is to issue a warning for every method not explicitly |
| implemented in the class, even if a method implementation is inherited |
| from the superclass. If you use the @code{-Wno-protocol} option, then |
| methods inherited from the superclass are considered to be implemented, |
| and no warning is issued for them. |
| |
| @item -Wselector |
| @opindex Wselector |
| Warn if multiple methods of different types for the same selector are |
| found during compilation. The check is performed on the list of methods |
| in the final stage of compilation. Additionally, a check is performed |
| for each selector appearing in a @code{@@selector(@dots{})} |
| expression, and a corresponding method for that selector has been found |
| during compilation. Because these checks scan the method table only at |
| the end of compilation, these warnings are not produced if the final |
| stage of compilation is not reached, for example because an error is |
| found during compilation, or because the @code{-fsyntax-only} option is |
| being used. |
| |
| @item -Wundeclared-selector |
| @opindex Wundeclared-selector |
| Warn if a @code{@@selector(@dots{})} expression referring to an |
| undeclared selector is found. A selector is considered undeclared if no |
| method with that name has been declared before the |
| @code{@@selector(@dots{})} expression, either explicitly in an |
| @code{@@interface} or @code{@@protocol} declaration, or implicitly in |
| an @code{@@implementation} section. This option always performs its |
| checks as soon as a @code{@@selector(@dots{})} expression is found, |
| while @code{-Wselector} only performs its checks in the final stage of |
| compilation. This also enforces the coding style convention |
| that methods and selectors must be declared before being used. |
| |
| @item -print-objc-runtime-info |
| @opindex print-objc-runtime-info |
| Generate C header describing the largest structure that is passed by |
| value, if any. |
| |
| @end table |
| |
| @node Language Independent Options |
| @section Options to Control Diagnostic Messages Formatting |
| @cindex options to control diagnostics formatting |
| @cindex diagnostic messages |
| @cindex message formatting |
| |
| Traditionally, diagnostic messages have been formatted irrespective of |
| the output device's aspect (e.g.@: its width, @dots{}). The options described |
| below can be used to control the diagnostic messages formatting |
| algorithm, e.g.@: how many characters per line, how often source location |
| information should be reported. Right now, only the C++ front end can |
| honor these options. However it is expected, in the near future, that |
| the remaining front ends would be able to digest them correctly. |
| |
| @table @gcctabopt |
| @item -fmessage-length=@var{n} |
| @opindex fmessage-length |
| Try to format error messages so that they fit on lines of about @var{n} |
| characters. The default is 72 characters for @command{g++} and 0 for the rest of |
| the front ends supported by GCC@. If @var{n} is zero, then no |
| line-wrapping will be done; each error message will appear on a single |
| line. |
| |
| @opindex fdiagnostics-show-location |
| @item -fdiagnostics-show-location=once |
| Only meaningful in line-wrapping mode. Instructs the diagnostic messages |
| reporter to emit @emph{once} source location information; that is, in |
| case the message is too long to fit on a single physical line and has to |
| be wrapped, the source location won't be emitted (as prefix) again, |
| over and over, in subsequent continuation lines. This is the default |
| behavior. |
| |
| @item -fdiagnostics-show-location=every-line |
| Only meaningful in line-wrapping mode. Instructs the diagnostic |
| messages reporter to emit the same source location information (as |
| prefix) for physical lines that result from the process of breaking |
| a message which is too long to fit on a single line. |
| |
| @end table |
| |
| @node Warning Options |
| @section Options to Request or Suppress Warnings |
| @cindex options to control warnings |
| @cindex warning messages |
| @cindex messages, warning |
| @cindex suppressing warnings |
| |
| Warnings are diagnostic messages that report constructions which |
| are not inherently erroneous but which are risky or suggest there |
| may have been an error. |
| |
| You can request many specific warnings with options beginning @samp{-W}, |
| for example @option{-Wimplicit} to request warnings on implicit |
| declarations. Each of these specific warning options also has a |
| negative form beginning @samp{-Wno-} to turn off warnings; |
| for example, @option{-Wno-implicit}. This manual lists only one of the |
| two forms, whichever is not the default. |
| |
| The following options control the amount and kinds of warnings produced |
| by GCC; for further, language-specific options also refer to |
| @ref{C++ Dialect Options} and @ref{Objective-C Dialect Options}. |
| |
| @table @gcctabopt |
| @cindex syntax checking |
| @item -fsyntax-only |
| @opindex fsyntax-only |
| Check the code for syntax errors, but don't do anything beyond that. |
| |
| @item -pedantic |
| @opindex pedantic |
| Issue all the warnings demanded by strict ISO C and ISO C++; |
| reject all programs that use forbidden extensions, and some other |
| programs that do not follow ISO C and ISO C++. For ISO C, follows the |
| version of the ISO C standard specified by any @option{-std} option used. |
| |
| Valid ISO C and ISO C++ programs should compile properly with or without |
| this option (though a rare few will require @option{-ansi} or a |
| @option{-std} option specifying the required version of ISO C)@. However, |
| without this option, certain GNU extensions and traditional C and C++ |
| features are supported as well. With this option, they are rejected. |
| |
| @option{-pedantic} does not cause warning messages for use of the |
| alternate keywords whose names begin and end with @samp{__}. Pedantic |
| warnings are also disabled in the expression that follows |
| @code{__extension__}. However, only system header files should use |
| these escape routes; application programs should avoid them. |
| @xref{Alternate Keywords}. |
| |
| Some users try to use @option{-pedantic} to check programs for strict ISO |
| C conformance. They soon find that it does not do quite what they want: |
| it finds some non-ISO practices, but not all---only those for which |
| ISO C @emph{requires} a diagnostic, and some others for which |
| diagnostics have been added. |
| |
| A feature to report any failure to conform to ISO C might be useful in |
| some instances, but would require considerable additional work and would |
| be quite different from @option{-pedantic}. We don't have plans to |
| support such a feature in the near future. |
| |
| Where the standard specified with @option{-std} represents a GNU |
| extended dialect of C, such as @samp{gnu89} or @samp{gnu99}, there is a |
| corresponding @dfn{base standard}, the version of ISO C on which the GNU |
| extended dialect is based. Warnings from @option{-pedantic} are given |
| where they are required by the base standard. (It would not make sense |
| for such warnings to be given only for features not in the specified GNU |
| C dialect, since by definition the GNU dialects of C include all |
| features the compiler supports with the given option, and there would be |
| nothing to warn about.) |
| |
| @item -pedantic-errors |
| @opindex pedantic-errors |
| Like @option{-pedantic}, except that errors are produced rather than |
| warnings. |
| |
| @item -w |
| @opindex w |
| Inhibit all warning messages. |
| |
| @item -Wno-import |
| @opindex Wno-import |
| Inhibit warning messages about the use of @samp{#import}. |
| |
| @item -Wchar-subscripts |
| @opindex Wchar-subscripts |
| Warn if an array subscript has type @code{char}. This is a common cause |
| of error, as programmers often forget that this type is signed on some |
| machines. |
| |
| @item -Wcomment |
| @opindex Wcomment |
| Warn whenever a comment-start sequence @samp{/*} appears in a @samp{/*} |
| comment, or whenever a Backslash-Newline appears in a @samp{//} comment. |
| |
| @item -Wformat |
| @opindex Wformat |
| Check calls to @code{printf} and @code{scanf}, etc., to make sure that |
| the arguments supplied have types appropriate to the format string |
| specified, and that the conversions specified in the format string make |
| sense. This includes standard functions, and others specified by format |
| attributes (@pxref{Function Attributes}), in the @code{printf}, |
| @code{scanf}, @code{strftime} and @code{strfmon} (an X/Open extension, |
| not in the C standard) families. |
| |
| The formats are checked against the format features supported by GNU |
| libc version 2.2. These include all ISO C90 and C99 features, as well |
| as features from the Single Unix Specification and some BSD and GNU |
| extensions. Other library implementations may not support all these |
| features; GCC does not support warning about features that go beyond a |
| particular library's limitations. However, if @option{-pedantic} is used |
| with @option{-Wformat}, warnings will be given about format features not |
| in the selected standard version (but not for @code{strfmon} formats, |
| since those are not in any version of the C standard). @xref{C Dialect |
| Options,,Options Controlling C Dialect}. |
| |
| Since @option{-Wformat} also checks for null format arguments for |
| several functions, @option{-Wformat} also implies @option{-Wnonnull}. |
| |
| @option{-Wformat} is included in @option{-Wall}. For more control over some |
| aspects of format checking, the options @option{-Wformat-y2k}, |
| @option{-Wno-format-extra-args}, @option{-Wno-format-zero-length}, |
| @option{-Wformat-nonliteral}, @option{-Wformat-security}, and |
| @option{-Wformat=2} are available, but are not included in @option{-Wall}. |
| |
| @item -Wformat-y2k |
| @opindex Wformat-y2k |
| If @option{-Wformat} is specified, also warn about @code{strftime} |
| formats which may yield only a two-digit year. |
| |
| @item -Wno-format-extra-args |
| @opindex Wno-format-extra-args |
| If @option{-Wformat} is specified, do not warn about excess arguments to a |
| @code{printf} or @code{scanf} format function. The C standard specifies |
| that such arguments are ignored. |
| |
| Where the unused arguments lie between used arguments that are |
| specified with @samp{$} operand number specifications, normally |
| warnings are still given, since the implementation could not know what |
| type to pass to @code{va_arg} to skip the unused arguments. However, |
| in the case of @code{scanf} formats, this option will suppress the |
| warning if the unused arguments are all pointers, since the Single |
| Unix Specification says that such unused arguments are allowed. |
| |
| @item -Wno-format-zero-length |
| @opindex Wno-format-zero-length |
| If @option{-Wformat} is specified, do not warn about zero-length formats. |
| The C standard specifies that zero-length formats are allowed. |
| |
| @item -Wformat-nonliteral |
| @opindex Wformat-nonliteral |
| If @option{-Wformat} is specified, also warn if the format string is not a |
| string literal and so cannot be checked, unless the format function |
| takes its format arguments as a @code{va_list}. |
| |
| @item -Wformat-security |
| @opindex Wformat-security |
| If @option{-Wformat} is specified, also warn about uses of format |
| functions that represent possible security problems. At present, this |
| warns about calls to @code{printf} and @code{scanf} functions where the |
| format string is not a string literal and there are no format arguments, |
| as in @code{printf (foo);}. This may be a security hole if the format |
| string came from untrusted input and contains @samp{%n}. (This is |
| currently a subset of what @option{-Wformat-nonliteral} warns about, but |
| in future warnings may be added to @option{-Wformat-security} that are not |
| included in @option{-Wformat-nonliteral}.) |
| |
| @item -Wformat=2 |
| @opindex Wformat=2 |
| Enable @option{-Wformat} plus format checks not included in |
| @option{-Wformat}. Currently equivalent to @samp{-Wformat |
| -Wformat-nonliteral -Wformat-security -Wformat-y2k}. |
| |
| @item -Wnonnull |
| @opindex Wnonnull |
| Warn about passing a null pointer for arguments marked as |
| requiring a non-null value by the @code{nonnull} function attribute. |
| |
| @option{-Wnonnull} is included in @option{-Wall} and @option{-Wformat}. It |
| can be disabled with the @option{-Wno-nonnull} option. |
| |
| @item -Winit-self @r{(C, C++, and Objective-C only)} |
| @opindex Winit-self |
| Warn about uninitialized variables which are initialized with themselves. |
| Note this option can only be used with the @option{-Wuninitialized} option, |
| which in turn only works with @option{-O1} and above. |
| |
| For example, GCC will warn about @code{i} being uninitialized in the |
| following snippet only when @option{-Winit-self} has been specified: |
| @smallexample |
| @group |
| int f() |
| @{ |
| int i = i; |
| return i; |
| @} |
| @end group |
| @end smallexample |
| |
| @item -Wimplicit-int |
| @opindex Wimplicit-int |
| Warn when a declaration does not specify a type. |
| |
| @item -Wimplicit-function-declaration |
| @itemx -Werror-implicit-function-declaration |
| @opindex Wimplicit-function-declaration |
| @opindex Werror-implicit-function-declaration |
| Give a warning (or error) whenever a function is used before being |
| declared. |
| |
| @item -Wimplicit |
| @opindex Wimplicit |
| Same as @option{-Wimplicit-int} and @option{-Wimplicit-function-declaration}. |
| |
| @item -Wmain |
| @opindex Wmain |
| Warn if the type of @samp{main} is suspicious. @samp{main} should be a |
| function with external linkage, returning int, taking either zero |
| arguments, two, or three arguments of appropriate types. |
| |
| @item -Wmissing-braces |
| @opindex Wmissing-braces |
| Warn if an aggregate or union initializer is not fully bracketed. In |
| the following example, the initializer for @samp{a} is not fully |
| bracketed, but that for @samp{b} is fully bracketed. |
| |
| @smallexample |
| int a[2][2] = @{ 0, 1, 2, 3 @}; |
| int b[2][2] = @{ @{ 0, 1 @}, @{ 2, 3 @} @}; |
| @end smallexample |
| |
| @item -Wparentheses |
| @opindex Wparentheses |
| Warn if parentheses are omitted in certain contexts, such |
| as when there is an assignment in a context where a truth value |
| is expected, or when operators are nested whose precedence people |
| often get confused about. |
| |
| Also warn about constructions where there may be confusion to which |
| @code{if} statement an @code{else} branch belongs. Here is an example of |
| such a case: |
| |
| @smallexample |
| @group |
| @{ |
| if (a) |
| if (b) |
| foo (); |
| else |
| bar (); |
| @} |
| @end group |
| @end smallexample |
| |
| In C, every @code{else} branch belongs to the innermost possible @code{if} |
| statement, which in this example is @code{if (b)}. This is often not |
| what the programmer expected, as illustrated in the above example by |
| indentation the programmer chose. When there is the potential for this |
| confusion, GCC will issue a warning when this flag is specified. |
| To eliminate the warning, add explicit braces around the innermost |
| @code{if} statement so there is no way the @code{else} could belong to |
| the enclosing @code{if}. The resulting code would look like this: |
| |
| @smallexample |
| @group |
| @{ |
| if (a) |
| @{ |
| if (b) |
| foo (); |
| else |
| bar (); |
| @} |
| @} |
| @end group |
| @end smallexample |
| |
| @item -Wsequence-point |
| @opindex Wsequence-point |
| Warn about code that may have undefined semantics because of violations |
| of sequence point rules in the C standard. |
| |
| The C standard defines the order in which expressions in a C program are |
| evaluated in terms of @dfn{sequence points}, which represent a partial |
| ordering between the execution of parts of the program: those executed |
| before the sequence point, and those executed after it. These occur |
| after the evaluation of a full expression (one which is not part of a |
| larger expression), after the evaluation of the first operand of a |
| @code{&&}, @code{||}, @code{? :} or @code{,} (comma) operator, before a |
| function is called (but after the evaluation of its arguments and the |
| expression denoting the called function), and in certain other places. |
| Other than as expressed by the sequence point rules, the order of |
| evaluation of subexpressions of an expression is not specified. All |
| these rules describe only a partial order rather than a total order, |
| since, for example, if two functions are called within one expression |
| with no sequence point between them, the order in which the functions |
| are called is not specified. However, the standards committee have |
| ruled that function calls do not overlap. |
| |
| It is not specified when between sequence points modifications to the |
| values of objects take effect. Programs whose behavior depends on this |
| have undefined behavior; the C standard specifies that ``Between the |
| previous and next sequence point an object shall have its stored value |
| modified at most once by the evaluation of an expression. Furthermore, |
| the prior value shall be read only to determine the value to be |
| stored.''. If a program breaks these rules, the results on any |
| particular implementation are entirely unpredictable. |
| |
| Examples of code with undefined behavior are @code{a = a++;}, @code{a[n] |
| = b[n++]} and @code{a[i++] = i;}. Some more complicated cases are not |
| diagnosed by this option, and it may give an occasional false positive |
| result, but in general it has been found fairly effective at detecting |
| this sort of problem in programs. |
| |
| The present implementation of this option only works for C programs. A |
| future implementation may also work for C++ programs. |
| |
| The C standard is worded confusingly, therefore there is some debate |
| over the precise meaning of the sequence point rules in subtle cases. |
| Links to discussions of the problem, including proposed formal |
| definitions, may be found on the GCC readings page, at |
| @w{@uref{http://gcc.gnu.org/readings.html}}. |
| |
| @item -Wreturn-type |
| @opindex Wreturn-type |
| Warn whenever a function is defined with a return-type that defaults to |
| @code{int}. Also warn about any @code{return} statement with no |
| return-value in a function whose return-type is not @code{void}. |
| |
| For C++, a function without return type always produces a diagnostic |
| message, even when @option{-Wno-return-type} is specified. The only |
| exceptions are @samp{main} and functions defined in system headers. |
| |
| @item -Wswitch |
| @opindex Wswitch |
| Warn whenever a @code{switch} statement has an index of enumerated type |
| and lacks a @code{case} for one or more of the named codes of that |
| enumeration. (The presence of a @code{default} label prevents this |
| warning.) @code{case} labels outside the enumeration range also |
| provoke warnings when this option is used. |
| |
| @item -Wswitch-default |
| @opindex Wswitch-switch |
| Warn whenever a @code{switch} statement does not have a @code{default} |
| case. |
| |
| @item -Wswitch-enum |
| @opindex Wswitch-enum |
| Warn whenever a @code{switch} statement has an index of enumerated type |
| and lacks a @code{case} for one or more of the named codes of that |
| enumeration. @code{case} labels outside the enumeration range also |
| provoke warnings when this option is used. |
| |
| @item -Wtrigraphs |
| @opindex Wtrigraphs |
| Warn if any trigraphs are encountered that might change the meaning of |
| the program (trigraphs within comments are not warned about). |
| |
| @item -Wunused-function |
| @opindex Wunused-function |
| Warn whenever a static function is declared but not defined or a |
| non\-inline static function is unused. |
| |
| @item -Wunused-label |
| @opindex Wunused-label |
| Warn whenever a label is declared but not used. |
| |
| To suppress this warning use the @samp{unused} attribute |
| (@pxref{Variable Attributes}). |
| |
| @item -Wunused-parameter |
| @opindex Wunused-parameter |
| Warn whenever a function parameter is unused aside from its declaration. |
| |
| To suppress this warning use the @samp{unused} attribute |
| (@pxref{Variable Attributes}). |
| |
| @item -Wunused-variable |
| @opindex Wunused-variable |
| Warn whenever a local variable or non-constant static variable is unused |
| aside from its declaration |
| |
| To suppress this warning use the @samp{unused} attribute |
| (@pxref{Variable Attributes}). |
| |
| @item -Wunused-value |
| @opindex Wunused-value |
| Warn whenever a statement computes a result that is explicitly not used. |
| |
| To suppress this warning cast the expression to @samp{void}. |
| |
| @item -Wunused |
| @opindex Wunused |
| All the above @option{-Wunused} options combined. |
| |
| In order to get a warning about an unused function parameter, you must |
| either specify @samp{-Wextra -Wunused} (note that @samp{-Wall} implies |
| @samp{-Wunused}), or separately specify @option{-Wunused-parameter}. |
| |
| @item -Wuninitialized |
| @opindex Wuninitialized |
| Warn if an automatic variable is used without first being initialized or |
| if a variable may be clobbered by a @code{setjmp} call. |
| |
| These warnings are possible only in optimizing compilation, |
| because they require data flow information that is computed only |
| when optimizing. If you don't specify @option{-O}, you simply won't |
| get these warnings. |
| |
| If you want to warn about code which uses the uninitialized value of the |
| variable in its own initializer, use the @option{-Winit-self} option. |
| |
| These warnings occur only for variables that are candidates for |
| register allocation. Therefore, they do not occur for a variable that |
| is declared @code{volatile}, or whose address is taken, or whose size |
| is other than 1, 2, 4 or 8 bytes. Also, they do not occur for |
| structures, unions or arrays, even when they are in registers. |
| |
| Note that there may be no warning about a variable that is used only |
| to compute a value that itself is never used, because such |
| computations may be deleted by data flow analysis before the warnings |
| are printed. |
| |
| These warnings are made optional because GCC is not smart |
| enough to see all the reasons why the code might be correct |
| despite appearing to have an error. Here is one example of how |
| this can happen: |
| |
| @smallexample |
| @group |
| @{ |
| int x; |
| switch (y) |
| @{ |
| case 1: x = 1; |
| break; |
| case 2: x = 4; |
| break; |
| case 3: x = 5; |
| @} |
| foo (x); |
| @} |
| @end group |
| @end smallexample |
| |
| @noindent |
| If the value of @code{y} is always 1, 2 or 3, then @code{x} is |
| always initialized, but GCC doesn't know this. Here is |
| another common case: |
| |
| @smallexample |
| @{ |
| int save_y; |
| if (change_y) save_y = y, y = new_y; |
| @dots{} |
| if (change_y) y = save_y; |
| @} |
| @end smallexample |
| |
| @noindent |
| This has no bug because @code{save_y} is used only if it is set. |
| |
| @cindex @code{longjmp} warnings |
| This option also warns when a non-volatile automatic variable might be |
| changed by a call to @code{longjmp}. These warnings as well are possible |
| only in optimizing compilation. |
| |
| The compiler sees only the calls to @code{setjmp}. It cannot know |
| where @code{longjmp} will be called; in fact, a signal handler could |
| call it at any point in the code. As a result, you may get a warning |
| even when there is in fact no problem because @code{longjmp} cannot |
| in fact be called at the place which would cause a problem. |
| |
| Some spurious warnings can be avoided if you declare all the functions |
| you use that never return as @code{noreturn}. @xref{Function |
| Attributes}. |
| |
| @item -Wunknown-pragmas |
| @opindex Wunknown-pragmas |
| @cindex warning for unknown pragmas |
| @cindex unknown pragmas, warning |
| @cindex pragmas, warning of unknown |
| Warn when a #pragma directive is encountered which is not understood by |
| GCC@. If this command line option is used, warnings will even be issued |
| for unknown pragmas in system header files. This is not the case if |
| the warnings were only enabled by the @option{-Wall} command line option. |
| |
| @item -Wstrict-aliasing |
| @opindex Wstrict-aliasing |
| This option is only active when @option{-fstrict-aliasing} is active. |
| It warns about code which might break the strict aliasing rules that the |
| compiler is using for optimization. The warning does not catch all |
| cases, but does attempt to catch the more common pitfalls. It is |
| included in @option{-Wall}. |
| |
| @item -Wall |
| @opindex Wall |
| All of the above @samp{-W} options combined. This enables all the |
| warnings about constructions that some users consider questionable, and |
| that are easy to avoid (or modify to prevent the warning), even in |
| conjunction with macros. This also enables some language-specific |
| warnings described in @ref{C++ Dialect Options} and |
| @ref{Objective-C Dialect Options}. |
| @end table |
| |
| The following @option{-W@dots{}} options are not implied by @option{-Wall}. |
| Some of them warn about constructions that users generally do not |
| consider questionable, but which occasionally you might wish to check |
| for; others warn about constructions that are necessary or hard to avoid |
| in some cases, and there is no simple way to modify the code to suppress |
| the warning. |
| |
| @table @gcctabopt |
| @item -Wextra |
| @opindex W |
| @opindex Wextra |
| (This option used to be called @option{-W}. The older name is still |
| supported, but the newer name is more descriptive.) Print extra warning |
| messages for these events: |
| |
| @itemize @bullet |
| @item |
| A function can return either with or without a value. (Falling |
| off the end of the function body is considered returning without |
| a value.) For example, this function would evoke such a |
| warning: |
| |
| @smallexample |
| @group |
| foo (a) |
| @{ |
| if (a > 0) |
| return a; |
| @} |
| @end group |
| @end smallexample |
| |
| @item |
| An expression-statement or the left-hand side of a comma expression |
| contains no side effects. |
| To suppress the warning, cast the unused expression to void. |
| For example, an expression such as @samp{x[i,j]} will cause a warning, |
| but @samp{x[(void)i,j]} will not. |
| |
| @item |
| An unsigned value is compared against zero with @samp{<} or @samp{>=}. |
| |
| @item |
| A comparison like @samp{x<=y<=z} appears; this is equivalent to |
| @samp{(x<=y ? 1 : 0) <= z}, which is a different interpretation from |
| that of ordinary mathematical notation. |
| |
| @item |
| Storage-class specifiers like @code{static} are not the first things in |
| a declaration. According to the C Standard, this usage is obsolescent. |
| |
| @item |
| The return type of a function has a type qualifier such as @code{const}. |
| Such a type qualifier has no effect, since the value returned by a |
| function is not an lvalue. (But don't warn about the GNU extension of |
| @code{volatile void} return types. That extension will be warned about |
| if @option{-pedantic} is specified.) |
| |
| @item |
| If @option{-Wall} or @option{-Wunused} is also specified, warn about unused |
| arguments. |
| |
| @item |
| A comparison between signed and unsigned values could produce an |
| incorrect result when the signed value is converted to unsigned. |
| (But don't warn if @option{-Wno-sign-compare} is also specified.) |
| |
| @item |
| An aggregate has an initializer which does not initialize all members. |
| For example, the following code would cause such a warning, because |
| @code{x.h} would be implicitly initialized to zero: |
| |
| @smallexample |
| struct s @{ int f, g, h; @}; |
| struct s x = @{ 3, 4 @}; |
| @end smallexample |
| |
| @item |
| A function parameter is declared without a type specifier in K&R-style |
| functions: |
| |
| @smallexample |
| void foo(bar) @{ @} |
| @end smallexample |
| |
| @item |
| An empty body occurs in an @samp{if} or @samp{else} statement. |
| |
| @item |
| A pointer is compared against integer zero with @samp{<}, @samp{<=}, |
| @samp{>}, or @samp{>=}. |
| |
| @item |
| A variable might be changed by @samp{longjmp} or @samp{vfork}. |
| |
| @item |
| Any of several floating-point events that often indicate errors, such as |
| overflow, underflow, loss of precision, etc. |
| |
| @item @r{(C++ only)} |
| An enumerator and a non-enumerator both appear in a conditional expression. |
| |
| @item @r{(C++ only)} |
| A non-static reference or non-static @samp{const} member appears in a |
| class without constructors. |
| |
| @item @r{(C++ only)} |
| Ambiguous virtual bases. |
| |
| @item @r{(C++ only)} |
| Subscripting an array which has been declared @samp{register}. |
| |
| @item @r{(C++ only)} |
| Taking the address of a variable which has been declared @samp{register}. |
| |
| @item @r{(C++ only)} |
| A base class is not initialized in a derived class' copy constructor. |
| @end itemize |
| |
| @item -Wno-div-by-zero |
| @opindex Wno-div-by-zero |
| @opindex Wdiv-by-zero |
| Do not warn about compile-time integer division by zero. Floating point |
| division by zero is not warned about, as it can be a legitimate way of |
| obtaining infinities and NaNs. |
| |
| @item -Wsystem-headers |
| @opindex Wsystem-headers |
| @cindex warnings from system headers |
| @cindex system headers, warnings from |
| Print warning messages for constructs found in system header files. |
| Warnings from system headers are normally suppressed, on the assumption |
| that they usually do not indicate real problems and would only make the |
| compiler output harder to read. Using this command line option tells |
| GCC to emit warnings from system headers as if they occurred in user |
| code. However, note that using @option{-Wall} in conjunction with this |
| option will @emph{not} warn about unknown pragmas in system |
| headers---for that, @option{-Wunknown-pragmas} must also be used. |
| |
| @item -Wfloat-equal |
| @opindex Wfloat-equal |
| Warn if floating point values are used in equality comparisons. |
| |
| The idea behind this is that sometimes it is convenient (for the |
| programmer) to consider floating-point values as approximations to |
| infinitely precise real numbers. If you are doing this, then you need |
| to compute (by analyzing the code, or in some other way) the maximum or |
| likely maximum error that the computation introduces, and allow for it |
| when performing comparisons (and when producing output, but that's a |
| different problem). In particular, instead of testing for equality, you |
| would check to see whether the two values have ranges that overlap; and |
| this is done with the relational operators, so equality comparisons are |
| probably mistaken. |
| |
| @item -Wtraditional @r{(C only)} |
| @opindex Wtraditional |
| Warn about certain constructs that behave differently in traditional and |
| ISO C@. Also warn about ISO C constructs that have no traditional C |
| equivalent, and/or problematic constructs which should be avoided. |
| |
| @itemize @bullet |
| @item |
| Macro parameters that appear within string literals in the macro body. |
| In traditional C macro replacement takes place within string literals, |
| but does not in ISO C@. |
| |
| @item |
| In traditional C, some preprocessor directives did not exist. |
| Traditional preprocessors would only consider a line to be a directive |
| if the @samp{#} appeared in column 1 on the line. Therefore |
| @option{-Wtraditional} warns about directives that traditional C |
| understands but would ignore because the @samp{#} does not appear as the |
| first character on the line. It also suggests you hide directives like |
| @samp{#pragma} not understood by traditional C by indenting them. Some |
| traditional implementations would not recognize @samp{#elif}, so it |
| suggests avoiding it altogether. |
| |
| @item |
| A function-like macro that appears without arguments. |
| |
| @item |
| The unary plus operator. |
| |
| @item |
| The @samp{U} integer constant suffix, or the @samp{F} or @samp{L} floating point |
| constant suffixes. (Traditional C does support the @samp{L} suffix on integer |
| constants.) Note, these suffixes appear in macros defined in the system |
| headers of most modern systems, e.g.@: the @samp{_MIN}/@samp{_MAX} macros in @code{<limits.h>}. |
| Use of these macros in user code might normally lead to spurious |
| warnings, however GCC's integrated preprocessor has enough context to |
| avoid warning in these cases. |
| |
| @item |
| A function declared external in one block and then used after the end of |
| the block. |
| |
| @item |
| A @code{switch} statement has an operand of type @code{long}. |
| |
| @item |
| A non-@code{static} function declaration follows a @code{static} one. |
| This construct is not accepted by some traditional C compilers. |
| |
| @item |
| The ISO type of an integer constant has a different width or |
| signedness from its traditional type. This warning is only issued if |
| the base of the constant is ten. I.e.@: hexadecimal or octal values, which |
| typically represent bit patterns, are not warned about. |
| |
| @item |
| Usage of ISO string concatenation is detected. |
| |
| @item |
| Initialization of automatic aggregates. |
| |
| @item |
| Identifier conflicts with labels. Traditional C lacks a separate |
| namespace for labels. |
| |
| @item |
| Initialization of unions. If the initializer is zero, the warning is |
| omitted. This is done under the assumption that the zero initializer in |
| user code appears conditioned on e.g.@: @code{__STDC__} to avoid missing |
| initializer warnings and relies on default initialization to zero in the |
| traditional C case. |
| |
| @item |
| Conversions by prototypes between fixed/floating point values and vice |
| versa. The absence of these prototypes when compiling with traditional |
| C would cause serious problems. This is a subset of the possible |
| conversion warnings, for the full set use @option{-Wconversion}. |
| |
| @item |
| Use of ISO C style function definitions. This warning intentionally is |
| @emph{not} issued for prototype declarations or variadic functions |
| because these ISO C features will appear in your code when using |
| libiberty's traditional C compatibility macros, @code{PARAMS} and |
| @code{VPARAMS}. This warning is also bypassed for nested functions |
| because that feature is already a GCC extension and thus not relevant to |
| traditional C compatibility. |
| @end itemize |
| |
| @item -Wdeclaration-after-statement @r{(C only)} |
| @opindex Wdeclaration-after-statement |
| Warn when a declaration is found after a statement in a block. This |
| construct, known from C++, was introduced with ISO C99 and is by default |
| allowed in GCC@. It is not supported by ISO C90 and was not supported by |
| GCC versions before GCC 3.0. @xref{Mixed Declarations}. |
| |
| @item -Wundef |
| @opindex Wundef |
| Warn if an undefined identifier is evaluated in an @samp{#if} directive. |
| |
| @item -Wendif-labels |
| @opindex Wendif-labels |
| Warn whenever an @samp{#else} or an @samp{#endif} are followed by text. |
| |
| @item -Wshadow |
| @opindex Wshadow |
| Warn whenever a local variable shadows another local variable, parameter or |
| global variable or whenever a built-in function is shadowed. |
| |
| @item -Wlarger-than-@var{len} |
| @opindex Wlarger-than |
| Warn whenever an object of larger than @var{len} bytes is defined. |
| |
| @item -Wpointer-arith |
| @opindex Wpointer-arith |
| Warn about anything that depends on the ``size of'' a function type or |
| of @code{void}. GNU C assigns these types a size of 1, for |
| convenience in calculations with @code{void *} pointers and pointers |
| to functions. |
| |
| @item -Wbad-function-cast @r{(C only)} |
| @opindex Wbad-function-cast |
| Warn whenever a function call is cast to a non-matching type. |
| For example, warn if @code{int malloc()} is cast to @code{anything *}. |
| |
| @item -Wcast-qual |
| @opindex Wcast-qual |
| Warn whenever a pointer is cast so as to remove a type qualifier from |
| the target type. For example, warn if a @code{const char *} is cast |
| to an ordinary @code{char *}. |
| |
| @item -Wcast-align |
| @opindex Wcast-align |
| Warn whenever a pointer is cast such that the required alignment of the |
| target is increased. For example, warn if a @code{char *} is cast to |
| an @code{int *} on machines where integers can only be accessed at |
| two- or four-byte boundaries. |
| |
| @item -Wwrite-strings |
| @opindex Wwrite-strings |
| When compiling C, give string constants the type @code{const |
| char[@var{length}]} so that |
| copying the address of one into a non-@code{const} @code{char *} |
| pointer will get a warning; when compiling C++, warn about the |
| deprecated conversion from string constants to @code{char *}. |
| These warnings will help you find at |
| compile time code that can try to write into a string constant, but |
| only if you have been very careful about using @code{const} in |
| declarations and prototypes. Otherwise, it will just be a nuisance; |
| this is why we did not make @option{-Wall} request these warnings. |
| |
| @item -Wconversion |
| @opindex Wconversion |
| Warn if a prototype causes a type conversion that is different from what |
| would happen to the same argument in the absence of a prototype. This |
| includes conversions of fixed point to floating and vice versa, and |
| conversions changing the width or signedness of a fixed point argument |
| except when the same as the default promotion. |
| |
| Also, warn if a negative integer constant expression is implicitly |
| converted to an unsigned type. For example, warn about the assignment |
| @code{x = -1} if @code{x} is unsigned. But do not warn about explicit |
| casts like @code{(unsigned) -1}. |
| |
| @item -Wsign-compare |
| @opindex Wsign-compare |
| @cindex warning for comparison of signed and unsigned values |
| @cindex comparison of signed and unsigned values, warning |
| @cindex signed and unsigned values, comparison warning |
| Warn when a comparison between signed and unsigned values could produce |
| an incorrect result when the signed value is converted to unsigned. |
| This warning is also enabled by @option{-Wextra}; to get the other warnings |
| of @option{-Wextra} without this warning, use @samp{-Wextra -Wno-sign-compare}. |
| |
| @item -Waggregate-return |
| @opindex Waggregate-return |
| Warn if any functions that return structures or unions are defined or |
| called. (In languages where you can return an array, this also elicits |
| a warning.) |
| |
| @item -Wstrict-prototypes @r{(C only)} |
| @opindex Wstrict-prototypes |
| Warn if a function is declared or defined without specifying the |
| argument types. (An old-style function definition is permitted without |
| a warning if preceded by a declaration which specifies the argument |
| types.) |
| |
| @item -Wold-style-definition @r{(C only)} |
| @opindex Wold-style-definition |
| Warn if an old-style function definition is used. A warning is given |
| even if there is a previous prototype. |
| |
| @item -Wmissing-prototypes @r{(C only)} |
| @opindex Wmissing-prototypes |
| Warn if a global function is defined without a previous prototype |
| declaration. This warning is issued even if the definition itself |
| provides a prototype. The aim is to detect global functions that fail |
| to be declared in header files. |
| |
| @item -Wmissing-declarations @r{(C only)} |
| @opindex Wmissing-declarations |
| Warn if a global function is defined without a previous declaration. |
| Do so even if the definition itself provides a prototype. |
| Use this option to detect global functions that are not declared in |
| header files. |
| |
| @item -Wmissing-noreturn |
| @opindex Wmissing-noreturn |
| Warn about functions which might be candidates for attribute @code{noreturn}. |
| Note these are only possible candidates, not absolute ones. Care should |
| be taken to manually verify functions actually do not ever return before |
| adding the @code{noreturn} attribute, otherwise subtle code generation |
| bugs could be introduced. You will not get a warning for @code{main} in |
| hosted C environments. |
| |
| @item -Wmissing-format-attribute |
| @opindex Wmissing-format-attribute |
| @opindex Wformat |
| If @option{-Wformat} is enabled, also warn about functions which might be |
| candidates for @code{format} attributes. Note these are only possible |
| candidates, not absolute ones. GCC will guess that @code{format} |
| attributes might be appropriate for any function that calls a function |
| like @code{vprintf} or @code{vscanf}, but this might not always be the |
| case, and some functions for which @code{format} attributes are |
| appropriate may not be detected. This option has no effect unless |
| @option{-Wformat} is enabled (possibly by @option{-Wall}). |
| |
| @item -Wno-multichar |
| @opindex Wno-multichar |
| @opindex Wmultichar |
| Do not warn if a multicharacter constant (@samp{'FOOF'}) is used. |
| Usually they indicate a typo in the user's code, as they have |
| implementation-defined values, and should not be used in portable code. |
| |
| @item -Wno-deprecated-declarations |
| @opindex Wno-deprecated-declarations |
| Do not warn about uses of functions, variables, and types marked as |
| deprecated by using the @code{deprecated} attribute. |
| (@pxref{Function Attributes}, @pxref{Variable Attributes}, |
| @pxref{Type Attributes}.) |
| |
| @item -Wpacked |
| @opindex Wpacked |
| Warn if a structure is given the packed attribute, but the packed |
| attribute has no effect on the layout or size of the structure. |
| Such structures may be mis-aligned for little benefit. For |
| instance, in this code, the variable @code{f.x} in @code{struct bar} |
| will be misaligned even though @code{struct bar} does not itself |
| have the packed attribute: |
| |
| @smallexample |
| @group |
| struct foo @{ |
| int x; |
| char a, b, c, d; |
| @} __attribute__((packed)); |
| struct bar @{ |
| char z; |
| struct foo f; |
| @}; |
| @end group |
| @end smallexample |
| |
| @item -Wpadded |
| @opindex Wpadded |
| Warn if padding is included in a structure, either to align an element |
| of the structure or to align the whole structure. Sometimes when this |
| happens it is possible to rearrange the fields of the structure to |
| reduce the padding and so make the structure smaller. |
| |
| @item -Wredundant-decls |
| @opindex Wredundant-decls |
| Warn if anything is declared more than once in the same scope, even in |
| cases where multiple declaration is valid and changes nothing. |
| |
| @item -Wnested-externs @r{(C only)} |
| @opindex Wnested-externs |
| Warn if an @code{extern} declaration is encountered within a function. |
| |
| @item -Wunreachable-code |
| @opindex Wunreachable-code |
| Warn if the compiler detects that code will never be executed. |
| |
| This option is intended to warn when the compiler detects that at |
| least a whole line of source code will never be executed, because |
| some condition is never satisfied or because it is after a |
| procedure that never returns. |
| |
| It is possible for this option to produce a warning even though there |
| are circumstances under which part of the affected line can be executed, |
| so care should be taken when removing apparently-unreachable code. |
| |
| For instance, when a function is inlined, a warning may mean that the |
| line is unreachable in only one inlined copy of the function. |
| |
| This option is not made part of @option{-Wall} because in a debugging |
| version of a program there is often substantial code which checks |
| correct functioning of the program and is, hopefully, unreachable |
| because the program does work. Another common use of unreachable |
| code is to provide behavior which is selectable at compile-time. |
| |
| @item -Winline |
| @opindex Winline |
| Warn if a function can not be inlined and it was declared as inline. |
| Even with this option, the compiler will not warn about failures to |
| inline functions declared in system headers. |
| |
| The compiler uses a variety of heuristics to determine whether or not |
| to inline a function. For example, the compiler takes into account |
| the size of the function being inlined and the the amount of inlining |
| that has already been done in the current function. Therefore, |
| seemingly insignificant changes in the source program can cause the |
| warnings produced by @option{-Winline} to appear or disappear. |
| |
| @item -Wno-invalid-offsetof @r{(C++ only)} |
| @opindex Wno-invalid-offsetof |
| Suppress warnings from applying the @samp{offsetof} macro to a non-POD |
| type. According to the 1998 ISO C++ standard, applying @samp{offsetof} |
| to a non-POD type is undefined. In existing C++ implementations, |
| however, @samp{offsetof} typically gives meaningful results even when |
| applied to certain kinds of non-POD types. (Such as a simple |
| @samp{struct} that fails to be a POD type only by virtue of having a |
| constructor.) This flag is for users who are aware that they are |
| writing nonportable code and who have deliberately chosen to ignore the |
| warning about it. |
| |
| The restrictions on @samp{offsetof} may be relaxed in a future version |
| of the C++ standard. |
| |
| @item -Winvalid-pch |
| @opindex Winvalid-pch |
| Warn if a precompiled header (@pxref{Precompiled Headers}) is found in |
| the search path but can't be used. |
| |
| @item -Wlong-long |
| @opindex Wlong-long |
| @opindex Wno-long-long |
| Warn if @samp{long long} type is used. This is default. To inhibit |
| the warning messages, use @option{-Wno-long-long}. Flags |
| @option{-Wlong-long} and @option{-Wno-long-long} are taken into account |
| only when @option{-pedantic} flag is used. |
| |
| @item -Wdisabled-optimization |
| @opindex Wdisabled-optimization |
| Warn if a requested optimization pass is disabled. This warning does |
| not generally indicate that there is anything wrong with your code; it |
| merely indicates that GCC's optimizers were unable to handle the code |
| effectively. Often, the problem is that your code is too big or too |
| complex; GCC will refuse to optimize programs when the optimization |
| itself is likely to take inordinate amounts of time. |
| |
| @item -Werror |
| @opindex Werror |
| Make all warnings into errors. |
| @end table |
| |
| @node Debugging Options |
| @section Options for Debugging Your Program or GCC |
| @cindex options, debugging |
| @cindex debugging information options |
| |
| GCC has various special options that are used for debugging |
| either your program or GCC: |
| |
| @table @gcctabopt |
| @item -g |
| @opindex g |
| Produce debugging information in the operating system's native format |
| (stabs, COFF, XCOFF, or DWARF)@. GDB can work with this debugging |
| information. |
| |
| On most systems that use stabs format, @option{-g} enables use of extra |
| debugging information that only GDB can use; this extra information |
| makes debugging work better in GDB but will probably make other debuggers |
| crash or |
| refuse to read the program. If you want to control for certain whether |
| to generate the extra information, use @option{-gstabs+}, @option{-gstabs}, |
| @option{-gxcoff+}, @option{-gxcoff}, or @option{-gvms} (see below). |
| |
| Unlike most other C compilers, GCC allows you to use @option{-g} with |
| @option{-O}. The shortcuts taken by optimized code may occasionally |
| produce surprising results: some variables you declared may not exist |
| at all; flow of control may briefly move where you did not expect it; |
| some statements may not be executed because they compute constant |
| results or their values were already at hand; some statements may |
| execute in different places because they were moved out of loops. |
| |
| Nevertheless it proves possible to debug optimized output. This makes |
| it reasonable to use the optimizer for programs that might have bugs. |
| |
| The following options are useful when GCC is generated with the |
| capability for more than one debugging format. |
| |
| @item -ggdb |
| @opindex ggdb |
| Produce debugging information for use by GDB@. This means to use the |
| most expressive format available (DWARF 2, stabs, or the native format |
| if neither of those are supported), including GDB extensions if at all |
| possible. |
| |
| @item -gstabs |
| @opindex gstabs |
| Produce debugging information in stabs format (if that is supported), |
| without GDB extensions. This is the format used by DBX on most BSD |
| systems. On MIPS, Alpha and System V Release 4 systems this option |
| produces stabs debugging output which is not understood by DBX or SDB@. |
| On System V Release 4 systems this option requires the GNU assembler. |
| |
| @item -feliminate-unused-debug-symbols |
| @opindex feliminate-unused-debug-symbols |
| Produce debugging information in stabs format (if that is supported), |
| for only symbols that are actually used. |
| |
| @item -gstabs+ |
| @opindex gstabs+ |
| Produce debugging information in stabs format (if that is supported), |
| using GNU extensions understood only by the GNU debugger (GDB)@. The |
| use of these extensions is likely to make other debuggers crash or |
| refuse to read the program. |
| |
| @item -gcoff |
| @opindex gcoff |
| Produce debugging information in COFF format (if that is supported). |
| This is the format used by SDB on most System V systems prior to |
| System V Release 4. |
| |
| @item -gxcoff |
| @opindex gxcoff |
| Produce debugging information in XCOFF format (if that is supported). |
| This is the format used by the DBX debugger on IBM RS/6000 systems. |
| |
| @item -gxcoff+ |
| @opindex gxcoff+ |
| Produce debugging information in XCOFF format (if that is supported), |
| using GNU extensions understood only by the GNU debugger (GDB)@. The |
| use of these extensions is likely to make other debuggers crash or |
| refuse to read the program, and may cause assemblers other than the GNU |
| assembler (GAS) to fail with an error. |
| |
| @item -gdwarf-2 |
| @opindex gdwarf-2 |
| Produce debugging information in DWARF version 2 format (if that is |
| supported). This is the format used by DBX on IRIX 6. |
| |
| @item -gvms |
| @opindex gvms |
| Produce debugging information in VMS debug format (if that is |
| supported). This is the format used by DEBUG on VMS systems. |
| |
| @item -g@var{level} |
| @itemx -ggdb@var{level} |
| @itemx -gstabs@var{level} |
| @itemx -gcoff@var{level} |
| @itemx -gxcoff@var{level} |
| @itemx -gvms@var{level} |
| Request debugging information and also use @var{level} to specify how |
| much information. The default level is 2. |
| |
| Level 1 produces minimal information, enough for making backtraces in |
| parts of the program that you don't plan to debug. This includes |
| descriptions of functions and external variables, but no information |
| about local variables and no line numbers. |
| |
| Level 3 includes extra information, such as all the macro definitions |
| present in the program. Some debuggers support macro expansion when |
| you use @option{-g3}. |
| |
| Note that in order to avoid confusion between DWARF1 debug level 2, |
| and DWARF2 @option{-gdwarf-2} does not accept a concatenated debug |
| level. Instead use an additional @option{-g@var{level}} option to |
| change the debug level for DWARF2. |
| |
| @item -feliminate-dwarf2-dups |
| @opindex feliminate-dwarf2-dups |
| Compress DWARF2 debugging information by eliminating duplicated |
| information about each symbol. This option only makes sense when |
| generating DWARF2 debugging information with @option{-gdwarf-2}. |
| |
| @cindex @command{prof} |
| @item -p |
| @opindex p |
| Generate extra code to write profile information suitable for the |
| analysis program @command{prof}. You must use this option when compiling |
| the source files you want data about, and you must also use it when |
| linking. |
| |
| @cindex @command{gprof} |
| @item -pg |
| @opindex pg |
| Generate extra code to write profile information suitable for the |
| analysis program @command{gprof}. You must use this option when compiling |
| the source files you want data about, and you must also use it when |
| linking. |
| |
| @item -Q |
| @opindex Q |
| Makes the compiler print out each function name as it is compiled, and |
| print some statistics about each pass when it finishes. |
| |
| @item -ftime-report |
| @opindex ftime-report |
| Makes the compiler print some statistics about the time consumed by each |
| pass when it finishes. |
| |
| @item -fmem-report |
| @opindex fmem-report |
| Makes the compiler print some statistics about permanent memory |
| allocation when it finishes. |
| |
| @item -fprofile-arcs |
| @opindex fprofile-arcs |
| Add code so that program flow @dfn{arcs} are instrumented. During |
| execution the program records how many times each branch and call is |
| executed and how many times it is taken or returns. When the compiled |
| program exits it saves this data to a file called |
| @file{@var{auxname}.gcda} for each source file. The data may be used for |
| profile-directed optimizations (@option{-fbranch-probabilities}), or for |
| test coverage analysis (@option{-ftest-coverage}). Each object file's |
| @var{auxname} is generated from the name of the output file, if |
| explicitly specified and it is not the final executable, otherwise it is |
| the basename of the source file. In both cases any suffix is removed |
| (e.g. @file{foo.gcda} for input file @file{dir/foo.c}, or |
| @file{dir/foo.gcda} for output file specified as @option{-o dir/foo.o}). |
| |
| @itemize |
| |
| @item |
| Compile the source files with @option{-fprofile-arcs} plus optimization |
| and code generation options. For test coverage analysis, use the |
| additional @option{-ftest-coverage} option. You do not need to profile |
| every source file in a program. |
| |
| @item |
| Link your object files with @option{-lgcov} or @option{-fprofile-arcs} |
| (the latter implies the former). |
| |
| @item |
| Run the program on a representative workload to generate the arc profile |
| information. This may be repeated any number of times. You can run |
| concurrent instances of your program, and provided that the file system |
| supports locking, the data files will be correctly updated. Also |
| @code{fork} calls are detected and correctly handled (double counting |
| will not happen). |
| |
| @item |
| For profile-directed optimizations, compile the source files again with |
| the same optimization and code generation options plus |
| @option{-fbranch-probabilities} (@pxref{Optimize Options,,Options that |
| Control Optimization}). |
| |
| @item |
| For test coverage analysis, use @command{gcov} to produce human readable |
| information from the @file{.gcno} and @file{.gcda} files. Refer to the |
| @command{gcov} documentation for further information. |
| |
| @end itemize |
| |
| With @option{-fprofile-arcs}, for each function of your program GCC |
| creates a program flow graph, then finds a spanning tree for the graph. |
| Only arcs that are not on the spanning tree have to be instrumented: the |
| compiler adds code to count the number of times that these arcs are |
| executed. When an arc is the only exit or only entrance to a block, the |
| instrumentation code can be added to the block; otherwise, a new basic |
| block must be created to hold the instrumentation code. |
| |
| @need 2000 |
| @item -ftest-coverage |
| @opindex ftest-coverage |
| Produce a notes file that the @command{gcov} code-coverage utility |
| (@pxref{Gcov,, @command{gcov}---a Test Coverage Program}) can use to |
| show program coverage. Each source file's note file is called |
| @file{@var{auxname}.gcno}. Refer to the @option{-fprofile-arcs} option |
| above for a description of @var{auxname} and instructions on how to |
| generate test coverage data. Coverage data will match the source files |
| more closely, if you do not optimize. |
| |
| @item -d@var{letters} |
| @opindex d |
| Says to make debugging dumps during compilation at times specified by |
| @var{letters}. This is used for debugging the compiler. The file names |
| for most of the dumps are made by appending a pass number and a word to |
| the @var{dumpname}. @var{dumpname} is generated from the name of the |
| output file, if explicitly specified and it is not an executable, |
| otherwise it is the basename of the source file. In both cases any |
| suffix is removed (e.g. @file{foo.01.rtl} or @file{foo.02.sibling}). |
| Here are the possible letters for use in @var{letters}, and their |
| meanings: |
| |
| @table @samp |
| @item A |
| @opindex dA |
| Annotate the assembler output with miscellaneous debugging information. |
| @item b |
| @opindex db |
| Dump after computing branch probabilities, to @file{@var{file}.12.bp}. |
| @item B |
| @opindex dB |
| Dump after block reordering, to @file{@var{file}.31.bbro}. |
| @item c |
| @opindex dc |
| Dump after instruction combination, to the file @file{@var{file}.20.combine}. |
| @item C |
| @opindex dC |
| Dump after the first if conversion, to the file @file{@var{file}.14.ce1}. |
| Also dump after the second if conversion, to the file @file{@var{file}.21.ce2}. |
| @item d |
| @opindex dd |
| Dump after branch target load optimization, to to @file{@var{file}.32.btl}. |
| Also dump after delayed branch scheduling, to @file{@var{file}.36.dbr}. |
| @item D |
| @opindex dD |
| Dump all macro definitions, at the end of preprocessing, in addition to |
| normal output. |
| @item E |
| @opindex dE |
| Dump after the third if conversion, to @file{@var{file}.30.ce3}. |
| @item f |
| @opindex df |
| Dump after control and data flow analysis, to @file{@var{file}.11.cfg}. |
| Also dump after life analysis, to @file{@var{file}.19.life}. |
| @item F |
| @opindex dF |
| Dump after purging @code{ADDRESSOF} codes, to @file{@var{file}.07.addressof}. |
| @item g |
| @opindex dg |
| Dump after global register allocation, to @file{@var{file}.25.greg}. |
| @item G |
| @opindex dG |
| Dump after GCSE, to @file{@var{file}.08.gcse}. |
| Also dump after jump bypassing and control flow optimizations, to |
| @file{@var{file}.10.bypass}. |
| @item h |
| @opindex dh |
| Dump after finalization of EH handling code, to @file{@var{file}.03.eh}. |
| @item i |
| @opindex di |
| Dump after sibling call optimizations, to @file{@var{file}.02.sibling}. |
| @item j |
| @opindex dj |
| Dump after the first jump optimization, to @file{@var{file}.04.jump}. |
| @item k |
| @opindex dk |
| Dump after conversion from registers to stack, to @file{@var{file}.34.stack}. |
| @item l |
| @opindex dl |
| Dump after local register allocation, to @file{@var{file}.24.lreg}. |
| @item L |
| @opindex dL |
| Dump after loop optimization passes, to @file{@var{file}.09.loop} and |
| @file{@var{file}.16.loop2}. |
| @item M |
| @opindex dM |
| Dump after performing the machine dependent reorganization pass, to |
| @file{@var{file}.35.mach}. |
| @item n |
| @opindex dn |
| Dump after register renumbering, to @file{@var{file}.29.rnreg}. |
| @item N |
| @opindex dN |
| Dump after the register move pass, to @file{@var{file}.22.regmove}. |
| @item o |
| @opindex do |
| Dump after post-reload optimizations, to @file{@var{file}.26.postreload}. |
| @item r |
| @opindex dr |
| Dump after RTL generation, to @file{@var{file}.01.rtl}. |
| @item R |
| @opindex dR |
| Dump after the second scheduling pass, to @file{@var{file}.33.sched2}. |
| @item s |
| @opindex ds |
| Dump after CSE (including the jump optimization that sometimes follows |
| CSE), to @file{@var{file}.06.cse}. |
| @item S |
| @opindex dS |
| Dump after the first scheduling pass, to @file{@var{file}.23.sched}. |
| @item t |
| @opindex dt |
| Dump after the second CSE pass (including the jump optimization that |
| sometimes follows CSE), to @file{@var{file}.18.cse2}. |
| @item T |
| @opindex dT |
| Dump after running tracer, to @file{@var{file}.15.tracer}. |
| @item u |
| @opindex du |
| Dump after null pointer elimination pass to @file{@var{file}.05.null}. |
| @item U |
| @opindex dU |
| Dump callgraph and unit-at-a-time optimization @file{@var{file}.00.unit}. |
| @item V |
| @opindex dV |
| Dump after the value profile transformations, to @file{@var{file}.13.vpt}. |
| @item w |
| @opindex dw |
| Dump after the second flow pass, to @file{@var{file}.27.flow2}. |
| @item z |
| @opindex dz |
| Dump after the peephole pass, to @file{@var{file}.28.peephole2}. |
| @item Z |
| @opindex dZ |
| Dump after constructing the web, to @file{@var{file}.17.web}. |
| @item a |
| @opindex da |
| Produce all the dumps listed above. |
| @item H |
| @opindex dH |
| Produce a core dump whenever an error occurs. |
| @item m |
| @opindex dm |
| Print statistics on memory usage, at the end of the run, to |
| standard error. |
| @item p |
| @opindex dp |
| Annotate the assembler output with a comment indicating which |
| pattern and alternative was used. The length of each instruction is |
| also printed. |
| @item P |
| @opindex dP |
| Dump the RTL in the assembler output as a comment before each instruction. |
| Also turns on @option{-dp} annotation. |
| @item v |
| @opindex dv |
| For each of the other indicated dump files (except for |
| @file{@var{file}.01.rtl}), dump a representation of the control flow graph |
| suitable for viewing with VCG to @file{@var{file}.@var{pass}.vcg}. |
| @item x |
| @opindex dx |
| Just generate RTL for a function instead of compiling it. Usually used |
| with @samp{r}. |
| @item y |
| @opindex dy |
| Dump debugging information during parsing, to standard error. |
| @end table |
| |
| @item -fdump-unnumbered |
| @opindex fdump-unnumbered |
| When doing debugging dumps (see @option{-d} option above), suppress instruction |
| numbers and line number note output. This makes it more feasible to |
| use diff on debugging dumps for compiler invocations with different |
| options, in particular with and without @option{-g}. |
| |
| @item -fdump-translation-unit @r{(C and C++ only)} |
| @itemx -fdump-translation-unit-@var{options} @r{(C and C++ only)} |
| @opindex fdump-translation-unit |
| Dump a representation of the tree structure for the entire translation |
| unit to a file. The file name is made by appending @file{.tu} to the |
| source file name. If the @samp{-@var{options}} form is used, @var{options} |
| controls the details of the dump as described for the |
| @option{-fdump-tree} options. |
| |
| @item -fdump-class-hierarchy @r{(C++ only)} |
| @itemx -fdump-class-hierarchy-@var{options} @r{(C++ only)} |
| @opindex fdump-class-hierarchy |
| Dump a representation of each class's hierarchy and virtual function |
| table layout to a file. The file name is made by appending @file{.class} |
| to the source file name. If the @samp{-@var{options}} form is used, |
| @var{options} controls the details of the dump as described for the |
| @option{-fdump-tree} options. |
| |
| @item -fdump-tree-@var{switch} @r{(C++ only)} |
| @itemx -fdump-tree-@var{switch}-@var{options} @r{(C++ only)} |
| @opindex fdump-tree |
| Control the dumping at various stages of processing the intermediate |
| language tree to a file. The file name is generated by appending a switch |
| specific suffix to the source file name. If the @samp{-@var{options}} |
| form is used, @var{options} is a list of @samp{-} separated options that |
| control the details of the dump. Not all options are applicable to all |
| dumps, those which are not meaningful will be ignored. The following |
| options are available |
| |
| @table @samp |
| @item address |
| Print the address of each node. Usually this is not meaningful as it |
| changes according to the environment and source file. Its primary use |
| is for tying up a dump file with a debug environment. |
| @item slim |
| Inhibit dumping of members of a scope or body of a function merely |
| because that scope has been reached. Only dump such items when they |
| are directly reachable by some other path. |
| @item all |
| Turn on all options. |
| @end table |
| |
| The following tree dumps are possible: |
| @table @samp |
| @item original |
| Dump before any tree based optimization, to @file{@var{file}.original}. |
| @item optimized |
| Dump after all tree based optimization, to @file{@var{file}.optimized}. |
| @item inlined |
| Dump after function inlining, to @file{@var{file}.inlined}. |
| @end table |
| |
| @item -frandom-seed=@var{string} |
| @opindex frandom-string |
| This option provides a seed that GCC uses when it would otherwise use |
| random numbers. It is used to generate certain symbol names |
| that have to be different in every compiled file. It is also used to |
| place unique stamps in coverage data files and the object files that |
| produce them. You can use the @option{-frandom-seed} option to produce |
| reproducibly identical object files. |
| |
| The @var{string} should be different for every file you compile. |
| |
| @item -fsched-verbose=@var{n} |
| @opindex fsched-verbose |
| On targets that use instruction scheduling, this option controls the |
| amount of debugging output the scheduler prints. This information is |
| written to standard error, unless @option{-dS} or @option{-dR} is |
| specified, in which case it is output to the usual dump |
| listing file, @file{.sched} or @file{.sched2} respectively. However |
| for @var{n} greater than nine, the output is always printed to standard |
| error. |
| |
| For @var{n} greater than zero, @option{-fsched-verbose} outputs the |
| same information as @option{-dRS}. For @var{n} greater than one, it |
| also output basic block probabilities, detailed ready list information |
| and unit/insn info. For @var{n} greater than two, it includes RTL |
| at abort point, control-flow and regions info. And for @var{n} over |
| four, @option{-fsched-verbose} also includes dependence info. |
| |
| @item -save-temps |
| @opindex save-temps |
| Store the usual ``temporary'' intermediate files permanently; place them |
| in the current directory and name them based on the source file. Thus, |
| compiling @file{foo.c} with @samp{-c -save-temps} would produce files |
| @file{foo.i} and @file{foo.s}, as well as @file{foo.o}. This creates a |
| preprocessed @file{foo.i} output file even though the compiler now |
| normally uses an integrated preprocessor. |
| |
| @item -time |
| @opindex time |
| Report the CPU time taken by each subprocess in the compilation |
| sequence. For C source files, this is the compiler proper and assembler |
| (plus the linker if linking is done). The output looks like this: |
| |
| @smallexample |
| # cc1 0.12 0.01 |
| # as 0.00 0.01 |
| @end smallexample |
| |
| The first number on each line is the ``user time,'' that is time spent |
| executing the program itself. The second number is ``system time,'' |
| time spent executing operating system routines on behalf of the program. |
| Both numbers are in seconds. |
| |
| @item -print-file-name=@var{library} |
| @opindex print-file-name |
| Print the full absolute name of the library file @var{library} that |
| would be used when linking---and don't do anything else. With this |
| option, GCC does not compile or link anything; it just prints the |
| file name. |
| |
| @item -print-multi-directory |
| @opindex print-multi-directory |
| Print the directory name corresponding to the multilib selected by any |
| other switches present in the command line. This directory is supposed |
| to exist in @env{GCC_EXEC_PREFIX}. |
| |
| @item -print-multi-lib |
| @opindex print-multi-lib |
| Print the mapping from multilib directory names to compiler switches |
| that enable them. The directory name is separated from the switches by |
| @samp{;}, and each switch starts with an @samp{@@} instead of the |
| @samp{-}, without spaces between multiple switches. This is supposed to |
| ease shell-processing. |
| |
| @item -print-prog-name=@var{program} |
| @opindex print-prog-name |
| Like @option{-print-file-name}, but searches for a program such as @samp{cpp}. |
| |
| @item -print-libgcc-file-name |
| @opindex print-libgcc-file-name |
| Same as @option{-print-file-name=libgcc.a}. |
| |
| This is useful when you use @option{-nostdlib} or @option{-nodefaultlibs} |
| but you do want to link with @file{libgcc.a}. You can do |
| |
| @smallexample |
| gcc -nostdlib @var{files}@dots{} `gcc -print-libgcc-file-name` |
| @end smallexample |
| |
| @item -print-search-dirs |
| @opindex print-search-dirs |
| Print the name of the configured installation directory and a list of |
| program and library directories @command{gcc} will search---and don't do anything else. |
| |
| This is useful when @command{gcc} prints the error message |
| @samp{installation problem, cannot exec cpp0: No such file or directory}. |
| To resolve this you either need to put @file{cpp0} and the other compiler |
| components where @command{gcc} expects to find them, or you can set the environment |
| variable @env{GCC_EXEC_PREFIX} to the directory where you installed them. |
| Don't forget the trailing '/'. |
| @xref{Environment Variables}. |
| |
| @item -dumpmachine |
| @opindex dumpmachine |
| Print the compiler's target machine (for example, |
| @samp{i686-pc-linux-gnu})---and don't do anything else. |
| |
| @item -dumpversion |
| @opindex dumpversion |
| Print the compiler version (for example, @samp{3.0})---and don't do |
| anything else. |
| |
| @item -dumpspecs |
| @opindex dumpspecs |
| Print the compiler's built-in specs---and don't do anything else. (This |
| is used when GCC itself is being built.) @xref{Spec Files}. |
| |
| @item -feliminate-unused-debug-types |
| @opindex feliminate-unused-debug-types |
| Normally, when producing DWARF2 output, GCC will emit debugging |
| information for all types declared in a compilation |
| unit, regardless of whether or not they are actually used |
| in that compilation unit. Sometimes this is useful, such as |
| if, in the debugger, you want to cast a value to a type that is |
| not actually used in your program (but is declared). More often, |
| however, this results in a significant amount of wasted space. |
| With this option, GCC will avoid producing debug symbol output |
| for types that are nowhere used in the source file being compiled. |
| @end table |
| |
| @node Optimize Options |
| @section Options That Control Optimization |
| @cindex optimize options |
| @cindex options, optimization |
| |
| These options control various sorts of optimizations. |
| |
| Without any optimization option, the compiler's goal is to reduce the |
| cost of compilation and to make debugging produce the expected |
| results. Statements are independent: if you stop the program with a |
| breakpoint between statements, you can then assign a new value to any |
| variable or change the program counter to any other statement in the |
| function and get exactly the results you would expect from the source |
| code. |
| |
| Turning on optimization flags makes the compiler attempt to improve |
| the performance and/or code size at the expense of compilation time |
| and possibly the ability to debug the program. |
| |
| The compiler performs optimization based on the knowledge it has of |
| the program. Using the @option{-funit-at-a-time} flag will allow the |
| compiler to consider information gained from later functions in the |
| file when compiling a function. Compiling multiple files at once to a |
| single output file (and using @option{-funit-at-a-time}) will allow |
| the compiler to use information gained from all of the files when |
| compiling each of them. |
| |
| Not all optimizations are controlled directly by a flag. Only |
| optimizations that have a flag are listed. |
| |
| @table @gcctabopt |
| @item -O |
| @itemx -O1 |
| @opindex O |
| @opindex O1 |
| Optimize. Optimizing compilation takes somewhat more time, and a lot |
| more memory for a large function. |
| |
| With @option{-O}, the compiler tries to reduce code size and execution |
| time, without performing any optimizations that take a great deal of |
| compilation time. |
| |
| @option{-O} turns on the following optimization flags: |
| @gccoptlist{-fdefer-pop @gol |
| -fmerge-constants @gol |
| -fthread-jumps @gol |
| -floop-optimize @gol |
| -fif-conversion @gol |
| -fif-conversion2 @gol |
| -fdelayed-branch @gol |
| -fguess-branch-probability @gol |
| -fcprop-registers} |
| |
| @option{-O} also turns on @option{-fomit-frame-pointer} on machines |
| where doing so does not interfere with debugging. |
| |
| @item -O2 |
| @opindex O2 |
| Optimize even more. GCC performs nearly all supported optimizations |
| that do not involve a space-speed tradeoff. The compiler does not |
| perform loop unrolling or function inlining when you specify @option{-O2}. |
| As compared to @option{-O}, this option increases both compilation time |
| and the performance of the generated code. |
| |
| @option{-O2} turns on all optimization flags specified by @option{-O}. It |
| also turns on the following optimization flags: |
| @gccoptlist{-fforce-mem @gol |
| -foptimize-sibling-calls @gol |
| -fstrength-reduce @gol |
| -fcse-follow-jumps -fcse-skip-blocks @gol |
| -frerun-cse-after-loop -frerun-loop-opt @gol |
| -fgcse -fgcse-lm -fgcse-sm -fgcse-las @gol |
| -fdelete-null-pointer-checks @gol |
| -fexpensive-optimizations @gol |
| -fregmove @gol |
| -fschedule-insns -fschedule-insns2 @gol |
| -fsched-interblock -fsched-spec @gol |
| -fcaller-saves @gol |
| -fpeephole2 @gol |
| -freorder-blocks -freorder-functions @gol |
| -fstrict-aliasing @gol |
| -funit-at-a-time @gol |
| -falign-functions -falign-jumps @gol |
| -falign-loops -falign-labels @gol |
| -fcrossjumping} |
| |
| Please note the warning under @option{-fgcse} about |
| invoking @option{-O2} on programs that use computed gotos. |
| |
| @item -O3 |
| @opindex O3 |
| Optimize yet more. @option{-O3} turns on all optimizations specified by |
| @option{-O2} and also turns on the @option{-finline-functions}, |
| @option{-fweb} and @option{-frename-registers} options. |
| |
| @item -O0 |
| @opindex O0 |
| Do not optimize. This is the default. |
| |
| @item -Os |
| @opindex Os |
| Optimize for size. @option{-Os} enables all @option{-O2} optimizations that |
| do not typically increase code size. It also performs further |
| optimizations designed to reduce code size. |
| |
| @option{-Os} disables the following optimization flags: |
| @gccoptlist{-falign-functions -falign-jumps -falign-loops @gol |
| -falign-labels -freorder-blocks -fprefetch-loop-arrays} |
| |
| If you use multiple @option{-O} options, with or without level numbers, |
| the last such option is the one that is effective. |
| @end table |
| |
| Options of the form @option{-f@var{flag}} specify machine-independent |
| flags. Most flags have both positive and negative forms; the negative |
| form of @option{-ffoo} would be @option{-fno-foo}. In the table |
| below, only one of the forms is listed---the one you typically will |
| use. You can figure out the other form by either removing @samp{no-} |
| or adding it. |
| |
| The following options control specific optimizations. They are either |
| activated by @option{-O} options or are related to ones that are. You |
| can use the following flags in the rare cases when ``fine-tuning'' of |
| optimizations to be performed is desired. |
| |
| @table @gcctabopt |
| @item -fno-default-inline |
| @opindex fno-default-inline |
| Do not make member functions inline by default merely because they are |
| defined inside the class scope (C++ only). Otherwise, when you specify |
| @w{@option{-O}}, member functions defined inside class scope are compiled |
| inline by default; i.e., you don't need to add @samp{inline} in front of |
| the member function name. |
| |
| @item -fno-defer-pop |
| @opindex fno-defer-pop |
| Always pop the arguments to each function call as soon as that function |
| returns. For machines which must pop arguments after a function call, |
| the compiler normally lets arguments accumulate on the stack for several |
| function calls and pops them all at once. |
| |
| Disabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fforce-mem |
| @opindex fforce-mem |
| Force memory operands to be copied into registers before doing |
| arithmetic on them. This produces better code by making all memory |
| references potential common subexpressions. When they are not common |
| subexpressions, instruction combination should eliminate the separate |
| register-load. |
| |
| Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fforce-addr |
| @opindex fforce-addr |
| Force memory address constants to be copied into registers before |
| doing arithmetic on them. This may produce better code just as |
| @option{-fforce-mem} may. |
| |
| @item -fomit-frame-pointer |
| @opindex fomit-frame-pointer |
| Don't keep the frame pointer in a register for functions that |
| don't need one. This avoids the instructions to save, set up and |
| restore frame pointers; it also makes an extra register available |
| in many functions. @strong{It also makes debugging impossible on |
| some machines.} |
| |
| On some machines, such as the VAX, this flag has no effect, because |
| the standard calling sequence automatically handles the frame pointer |
| and nothing is saved by pretending it doesn't exist. The |
| machine-description macro @code{FRAME_POINTER_REQUIRED} controls |
| whether a target machine supports this flag. @xref{Registers,,Register |
| Usage, gccint, GNU Compiler Collection (GCC) Internals}. |
| |
| Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -foptimize-sibling-calls |
| @opindex foptimize-sibling-calls |
| Optimize sibling and tail recursive calls. |
| |
| Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fno-inline |
| @opindex fno-inline |
| Don't pay attention to the @code{inline} keyword. Normally this option |
| is used to keep the compiler from expanding any functions inline. |
| Note that if you are not optimizing, no functions can be expanded inline. |
| |
| @item -finline-functions |
| @opindex finline-functions |
| Integrate all simple functions into their callers. The compiler |
| heuristically decides which functions are simple enough to be worth |
| integrating in this way. |
| |
| If all calls to a given function are integrated, and the function is |
| declared @code{static}, then the function is normally not output as |
| assembler code in its own right. |
| |
| Enabled at level @option{-O3}. |
| |
| @item -finline-limit=@var{n} |
| @opindex finline-limit |
| By default, GCC limits the size of functions that can be inlined. This flag |
| allows the control of this limit for functions that are explicitly marked as |
| inline (i.e., marked with the inline keyword or defined within the class |
| definition in c++). @var{n} is the size of functions that can be inlined in |
| number of pseudo instructions (not counting parameter handling). The default |
| value of @var{n} is 600. |
| Increasing this value can result in more inlined code at |
| the cost of compilation time and memory consumption. Decreasing usually makes |
| the compilation faster and less code will be inlined (which presumably |
| means slower programs). This option is particularly useful for programs that |
| use inlining heavily such as those based on recursive templates with C++. |
| |
| Inlining is actually controlled by a number of parameters, which may be |
| specified individually by using @option{--param @var{name}=@var{value}}. |
| The @option{-finline-limit=@var{n}} option sets some of these parameters |
| as follows: |
| |
| @table @gcctabopt |
| @item max-inline-insns-single |
| is set to @var{n}/2. |
| @item max-inline-insns-auto |
| is set to @var{n}/2. |
| @item min-inline-insns |
| is set to 130 or @var{n}/4, whichever is smaller. |
| @item max-inline-insns-rtl |
| is set to @var{n}. |
| @end table |
| |
| See below for a documentation of the individual |
| parameters controlling inlining. |
| |
| @emph{Note:} pseudo instruction represents, in this particular context, an |
| abstract measurement of function's size. In no way, it represents a count |
| of assembly instructions and as such its exact meaning might change from one |
| release to an another. |
| |
| @item -fkeep-inline-functions |
| @opindex fkeep-inline-functions |
| Even if all calls to a given function are integrated, and the function |
| is declared @code{static}, nevertheless output a separate run-time |
| callable version of the function. This switch does not affect |
| @code{extern inline} functions. |
| |
| @item -fkeep-static-consts |
| @opindex fkeep-static-consts |
| Emit variables declared @code{static const} when optimization isn't turned |
| on, even if the variables aren't referenced. |
| |
| GCC enables this option by default. If you want to force the compiler to |
| check if the variable was referenced, regardless of whether or not |
| optimization is turned on, use the @option{-fno-keep-static-consts} option. |
| |
| @item -fmerge-constants |
| Attempt to merge identical constants (string constants and floating point |
| constants) across compilation units. |
| |
| This option is the default for optimized compilation if the assembler and |
| linker support it. Use @option{-fno-merge-constants} to inhibit this |
| behavior. |
| |
| Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fmerge-all-constants |
| Attempt to merge identical constants and identical variables. |
| |
| This option implies @option{-fmerge-constants}. In addition to |
| @option{-fmerge-constants} this considers e.g. even constant initialized |
| arrays or initialized constant variables with integral or floating point |
| types. Languages like C or C++ require each non-automatic variable to |
| have distinct location, so using this option will result in non-conforming |
| behavior. |
| |
| @item -fnew-ra |
| @opindex fnew-ra |
| Use a graph coloring register allocator. Currently this option is meant |
| only for testing. Users should not specify this option, since it is not |
| yet ready for production use. |
| |
| @item -fno-branch-count-reg |
| @opindex fno-branch-count-reg |
| Do not use ``decrement and branch'' instructions on a count register, |
| but instead generate a sequence of instructions that decrement a |
| register, compare it against zero, then branch based upon the result. |
| This option is only meaningful on architectures that support such |
| instructions, which include x86, PowerPC, IA-64 and S/390. |
| |
| The default is @option{-fbranch-count-reg}, enabled when |
| @option{-fstrength-reduce} is enabled. |
| |
| @item -fno-function-cse |
| @opindex fno-function-cse |
| Do not put function addresses in registers; make each instruction that |
| calls a constant function contain the function's address explicitly. |
| |
| This option results in less efficient code, but some strange hacks |
| that alter the assembler output may be confused by the optimizations |
| performed when this option is not used. |
| |
| The default is @option{-ffunction-cse} |
| |
| @item -fno-zero-initialized-in-bss |
| @opindex fno-zero-initialized-in-bss |
| If the target supports a BSS section, GCC by default puts variables that |
| are initialized to zero into BSS@. This can save space in the resulting |
| code. |
| |
| This option turns off this behavior because some programs explicitly |
| rely on variables going to the data section. E.g., so that the |
| resulting executable can find the beginning of that section and/or make |
| assumptions based on that. |
| |
| The default is @option{-fzero-initialized-in-bss}. |
| |
| @item -fstrength-reduce |
| @opindex fstrength-reduce |
| Perform the optimizations of loop strength reduction and |
| elimination of iteration variables. |
| |
| Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fthread-jumps |
| @opindex fthread-jumps |
| Perform optimizations where we check to see if a jump branches to a |
| location where another comparison subsumed by the first is found. If |
| so, the first branch is redirected to either the destination of the |
| second branch or a point immediately following it, depending on whether |
| the condition is known to be true or false. |
| |
| Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fcse-follow-jumps |
| @opindex fcse-follow-jumps |
| In common subexpression elimination, scan through jump instructions |
| when the target of the jump is not reached by any other path. For |
| example, when CSE encounters an @code{if} statement with an |
| @code{else} clause, CSE will follow the jump when the condition |
| tested is false. |
| |
| Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fcse-skip-blocks |
| @opindex fcse-skip-blocks |
| This is similar to @option{-fcse-follow-jumps}, but causes CSE to |
| follow jumps which conditionally skip over blocks. When CSE |
| encounters a simple @code{if} statement with no else clause, |
| @option{-fcse-skip-blocks} causes CSE to follow the jump around the |
| body of the @code{if}. |
| |
| Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -frerun-cse-after-loop |
| @opindex frerun-cse-after-loop |
| Re-run common subexpression elimination after loop optimizations has been |
| performed. |
| |
| Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -frerun-loop-opt |
| @opindex frerun-loop-opt |
| Run the loop optimizer twice. |
| |
| Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fgcse |
| @opindex fgcse |
| Perform a global common subexpression elimination pass. |
| This pass also performs global constant and copy propagation. |
| |
| @emph{Note:} When compiling a program using computed gotos, a GCC |
| extension, you may get better runtime performance if you disable |
| the global common subexpression elimination pass by adding |
| @option{-fno-gcse} to the command line. |
| |
| Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fgcse-lm |
| @opindex fgcse-lm |
| When @option{-fgcse-lm} is enabled, global common subexpression elimination will |
| attempt to move loads which are only killed by stores into themselves. This |
| allows a loop containing a load/store sequence to be changed to a load outside |
| the loop, and a copy/store within the loop. |
| |
| Enabled by default when gcse is enabled. |
| |
| @item -fgcse-sm |
| @opindex fgcse-sm |
| When @option{-fgcse-sm} is enabled, a store motion pass is run after |
| global common subexpression elimination. This pass will attempt to move |
| stores out of loops. When used in conjunction with @option{-fgcse-lm}, |
| loops containing a load/store sequence can be changed to a load before |
| the loop and a store after the loop. |
| |
| Enabled by default when gcse is enabled. |
| |
| @item -fgcse-las |
| @opindex fgcse-las |
| When @option{-fgcse-las} is enabled, the global common subexpression |
| elimination pass eliminates redundant loads that come after stores to the |
| same memory location (both partial and full redundancies). |
| |
| Enabled by default when gcse is enabled. |
| |
| @item -floop-optimize |
| @opindex floop-optimize |
| Perform loop optimizations: move constant expressions out of loops, simplify |
| exit test conditions and optionally do strength-reduction and loop unrolling as |
| well. |
| |
| Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fcrossjumping |
| @opindex crossjumping |
| Perform cross-jumping transformation. This transformation unifies equivalent code and save code size. The |
| resulting code may or may not perform better than without cross-jumping. |
| |
| Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fif-conversion |
| @opindex if-conversion |
| Attempt to transform conditional jumps into branch-less equivalents. This |
| include use of conditional moves, min, max, set flags and abs instructions, and |
| some tricks doable by standard arithmetics. The use of conditional execution |
| on chips where it is available is controlled by @code{if-conversion2}. |
| |
| Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fif-conversion2 |
| @opindex if-conversion2 |
| Use conditional execution (where available) to transform conditional jumps into |
| branch-less equivalents. |
| |
| Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fdelete-null-pointer-checks |
| @opindex fdelete-null-pointer-checks |
| Use global dataflow analysis to identify and eliminate useless checks |
| for null pointers. The compiler assumes that dereferencing a null |
| pointer would have halted the program. If a pointer is checked after |
| it has already been dereferenced, it cannot be null. |
| |
| In some environments, this assumption is not true, and programs can |
| safely dereference null pointers. Use |
| @option{-fno-delete-null-pointer-checks} to disable this optimization |
| for programs which depend on that behavior. |
| |
| Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fexpensive-optimizations |
| @opindex fexpensive-optimizations |
| Perform a number of minor optimizations that are relatively expensive. |
| |
| Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -foptimize-register-move |
| @itemx -fregmove |
| @opindex foptimize-register-move |
| @opindex fregmove |
| Attempt to reassign register numbers in move instructions and as |
| operands of other simple instructions in order to maximize the amount of |
| register tying. This is especially helpful on machines with two-operand |
| instructions. |
| |
| Note @option{-fregmove} and @option{-foptimize-register-move} are the same |
| optimization. |
| |
| Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fdelayed-branch |
| @opindex fdelayed-branch |
| If supported for the target machine, attempt to reorder instructions |
| to exploit instruction slots available after delayed branch |
| instructions. |
| |
| Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fschedule-insns |
| @opindex fschedule-insns |
| If supported for the target machine, attempt to reorder instructions to |
| eliminate execution stalls due to required data being unavailable. This |
| helps machines that have slow floating point or memory load instructions |
| by allowing other instructions to be issued until the result of the load |
| or floating point instruction is required. |
| |
| Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fschedule-insns2 |
| @opindex fschedule-insns2 |
| Similar to @option{-fschedule-insns}, but requests an additional pass of |
| instruction scheduling after register allocation has been done. This is |
| especially useful on machines with a relatively small number of |
| registers and where memory load instructions take more than one cycle. |
| |
| Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fno-sched-interblock |
| @opindex fno-sched-interblock |
| Don't schedule instructions across basic blocks. This is normally |
| enabled by default when scheduling before register allocation, i.e.@: |
| with @option{-fschedule-insns} or at @option{-O2} or higher. |
| |
| @item -fno-sched-spec |
| @opindex fno-sched-spec |
| Don't allow speculative motion of non-load instructions. This is normally |
| enabled by default when scheduling before register allocation, i.e.@: |
| with @option{-fschedule-insns} or at @option{-O2} or higher. |
| |
| @item -fsched-spec-load |
| @opindex fsched-spec-load |
| Allow speculative motion of some load instructions. This only makes |
| sense when scheduling before register allocation, i.e.@: with |
| @option{-fschedule-insns} or at @option{-O2} or higher. |
| |
| @item -fsched-spec-load-dangerous |
| @opindex fsched-spec-load-dangerous |
| Allow speculative motion of more load instructions. This only makes |
| sense when scheduling before register allocation, i.e.@: with |
| @option{-fschedule-insns} or at @option{-O2} or higher. |
| |
| @item -fsched-stalled-insns=@var{n} |
| @opindex fsched-stalled-insns |
| Define how many insns (if any) can be moved prematurely from the queue |
| of stalled insns into the ready list, during the second scheduling pass. |
| |
| @item -fsched-stalled-insns-dep=@var{n} |
| @opindex fsched-stalled-insns-dep |
| Define how many insn groups (cycles) will be examined for a dependency |
| on a stalled insn that is candidate for premature removal from the queue |
| of stalled insns. Has an effect only during the second scheduling pass, |
| and only if @option{-fsched-stalled-insns} is used and its value is not zero. |
| |
| @item -fsched2-use-superblocks |
| @opindex fsched2-use-superblocks |
| When scheduling after register allocation, do use superblock scheduling |
| algorithm. Superblock scheduling allows motion across basic block boundaries |
| resulting on faster schedules. This option is experimental, as not all machine |
| descriptions used by GCC model the CPU closely enough to avoid unreliable |
| results from the algorithm. |
| |
| This only makes sense when scheduling after register allocation, i.e.@: with |
| @option{-fschedule-insns2} or at @option{-O2} or higher. |
| |
| @item -fsched2-use-traces |
| @opindex fsched2-use-traces |
| Use @option{-fsched2-use-superblocks} algorithm when scheduling after register |
| allocation and additionally perform code duplication in order to increase the |
| size of superblocks using tracer pass. See @option{-ftracer} for details on |
| trace formation. |
| |
| This mode should produce faster but significantly longer programs. Also |
| without @code{-fbranch-probabilities} the traces constructed may not match the |
| reality and hurt the performance. This only makes |
| sense when scheduling after register allocation, i.e.@: with |
| @option{-fschedule-insns2} or at @option{-O2} or higher. |
| |
| @item -fcaller-saves |
| @opindex fcaller-saves |
| Enable values to be allocated in registers that will be clobbered by |
| function calls, by emitting extra instructions to save and restore the |
| registers around such calls. Such allocation is done only when it |
| seems to result in better code than would otherwise be produced. |
| |
| This option is always enabled by default on certain machines, usually |
| those which have no call-preserved registers to use instead. |
| |
| Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fmove-all-movables |
| @opindex fmove-all-movables |
| Forces all invariant computations in loops to be moved |
| outside the loop. |
| |
| @item -freduce-all-givs |
| @opindex freduce-all-givs |
| Forces all general-induction variables in loops to be |
| strength-reduced. |
| |
| @emph{Note:} When compiling programs written in Fortran, |
| @option{-fmove-all-movables} and @option{-freduce-all-givs} are enabled |
| by default when you use the optimizer. |
| |
| These options may generate better or worse code; results are highly |
| dependent on the structure of loops within the source code. |
| |
| These two options are intended to be removed someday, once |
| they have helped determine the efficacy of various |
| approaches to improving loop optimizations. |
| |
| Please contact @w{@email{gcc@@gcc.gnu.org}}, and describe how use of |
| these options affects the performance of your production code. |
| Examples of code that runs @emph{slower} when these options are |
| @emph{enabled} are very valuable. |
| |
| @item -fno-peephole |
| @itemx -fno-peephole2 |
| @opindex fno-peephole |
| @opindex fno-peephole2 |
| Disable any machine-specific peephole optimizations. The difference |
| between @option{-fno-peephole} and @option{-fno-peephole2} is in how they |
| are implemented in the compiler; some targets use one, some use the |
| other, a few use both. |
| |
| @option{-fpeephole} is enabled by default. |
| @option{-fpeephole2} enabled at levels @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fno-guess-branch-probability |
| @opindex fno-guess-branch-probability |
| Do not guess branch probabilities using a randomized model. |
| |
| Sometimes GCC will opt to use a randomized model to guess branch |
| probabilities, when none are available from either profiling feedback |
| (@option{-fprofile-arcs}) or @samp{__builtin_expect}. This means that |
| different runs of the compiler on the same program may produce different |
| object code. |
| |
| In a hard real-time system, people don't want different runs of the |
| compiler to produce code that has different behavior; minimizing |
| non-determinism is of paramount import. This switch allows users to |
| reduce non-determinism, possibly at the expense of inferior |
| optimization. |
| |
| The default is @option{-fguess-branch-probability} at levels |
| @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -freorder-blocks |
| @opindex freorder-blocks |
| Reorder basic blocks in the compiled function in order to reduce number of |
| taken branches and improve code locality. |
| |
| Enabled at levels @option{-O2}, @option{-O3}. |
| |
| @item -freorder-functions |
| @opindex freorder-functions |
| Reorder basic blocks in the compiled function in order to reduce number of |
| taken branches and improve code locality. This is implemented by using special |
| subsections @code{.text.hot} for most frequently executed functions and |
| @code{.text.unlikely} for unlikely executed functions. Reordering is done by |
| the linker so object file format must support named sections and linker must |
| place them in a reasonable way. |
| |
| Also profile feedback must be available in to make this option effective. See |
| @option{-fprofile-arcs} for details. |
| |
| Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}. |
| |
| @item -fstrict-aliasing |
| @opindex fstrict-aliasing |
| Allows the compiler to assume the strictest aliasing rules applicable to |
| the language being compiled. For C (and C++), this activates |
| optimizations based on the type of expressions. In particular, an |
| object of one type is assumed never to reside at the same address as an |
| object of a different type, unless the types are almost the same. For |
| example, an @code{unsigned int} can alias an @code{int}, but not a |
| @code{void*} or a @code{double}. A character type may alias any other |
| type. |
| |
| |