Next:Options Controlling C++ Dialect, Previous:Compiling C++ Programs, Up:GCC Command Options [Contents][Index]
The following options control the dialect of C (or languages derivedfrom C, such as C++, Objective-C and Objective-C++) that the compileraccepts:
-ansi ¶--ansiIn C mode, this is equivalent to-std=c90. In C++ mode, it isequivalent to-std=c++98.
-std= ¶Determine the language standard. SeeLanguage StandardsSupported by GCC, for details of these standard versions. This optionis currently only supported when compiling C or C++.
The compiler can accept several base standards, such as ‘c90’ or‘c++98’, and GNU dialects of those standards, such as‘gnu90’ or ‘gnu++98’. When a base standard is specified, thecompiler accepts all programs following that standard plus thoseusing GNU extensions that do not contradict it. For example,-std=c90 turns off certain features of GCC that areincompatible with ISO C90, such as theasm andtypeofkeywords, but not other GNU extensions that do not have a meaning inISO C90, such as omitting the middle term of a?:expression. On the other hand, when a GNU dialect of a standard isspecified, all features supported by the compiler are enabled, even whenthose features change the meaning of the base standard. As a result, somestrict-conforming programs may be rejected. The particular standardis used by-Wpedantic to identify which features are GNUextensions given that version of the standard. For example-std=gnu90 -Wpedantic warns about C++ style ‘//’comments, while-std=gnu99 -Wpedantic does not.
A value for this option must be provided; possible values are
Support all ISO C90 programs (certain GNU extensions that conflictwith ISO C90 are disabled). Same as-ansi for C code.
ISO C90 as modified in amendment 1.
ISO C99. This standard is substantially completely supported, modulobugs and floating-point issues(mainly but not entirely relating to optional C99 features fromAnnexes F and G). Seehttps://gcc.gnu.org/projects/c-status.html for more information.The names ‘c9x’ and ‘iso9899:199x’ are deprecated.
ISO C11, the 2011 revision of the ISO C standard. This standard issubstantially completely supported, modulo bugs, floating-point issues(mainly but not entirely relating to optional C11 features fromAnnexes F and G) and the optional Annexes K (Bounds-checkinginterfaces) and L (Analyzability). The name ‘c1x’ is deprecated.
ISO C17, the 2017 revision of the ISO C standard(published in 2018). This standard issame as C11 except for corrections of defects (all of which are alsoapplied with-std=c11) and a new value of__STDC_VERSION__, and so is supported to the same extent as C11.
ISO C23, the 2023 revision of the ISO C standard (published in 2024). Thename ‘c2x’ is deprecated.
The next version of the ISO C standard, still under development. Thesupport for this version is experimental and incomplete.
GNU dialect of ISO C90 (including some C99 features).
GNU dialect of ISO C99. The name ‘gnu9x’ is deprecated.
GNU dialect of ISO C11.The name ‘gnu1x’ is deprecated.
GNU dialect of ISO C17.
GNU dialect of ISO C23. This is the default for C code. The name‘gnu2x’ is deprecated.
The next version of the ISO C standard, still under development, plusGNU extensions. The support for this version is experimental andincomplete. The name ‘gnu2x’ is deprecated.
The 1998 ISO C++ standard plus the 2003 technical corrigendum and someadditional defect reports. Same as-ansi for C++ code.
GNU dialect of-std=c++98.
The 2011 ISO C++ standard plus amendments.The name ‘c++0x’ is deprecated.
GNU dialect of-std=c++11.The name ‘gnu++0x’ is deprecated.
The 2014 ISO C++ standard plus amendments.The name ‘c++1y’ is deprecated.
GNU dialect of-std=c++14.The name ‘gnu++1y’ is deprecated.
The 2017 ISO C++ standard plus amendments.The name ‘c++1z’ is deprecated.
GNU dialect of-std=c++17.The name ‘gnu++1z’ is deprecated.
The 2020 ISO C++ standard plus amendments.C++20 modules support is still experimental and needs to beenabled with-fmodules option.The name ‘c++2a’ is deprecated.
GNU dialect of-std=c++20.This is the default for C++ code.C++20 modules support is still experimental and needs to beenabled with-fmodules option.The name ‘gnu++2a’ is deprecated.
The 2023 ISO C++ standard plus amendments (published in 2024).Support is experimental, and could change in incompatible ways infuture releases.The name ‘c++2b’ is deprecated.
GNU dialect of-std=c++23.Support is experimental, and could change in incompatible ways infuture releases.The name ‘gnu++2b’ is deprecated.
The next revision of the ISO C++ standard, planned for2026. Support is highly experimental, and will almost certainlychange in incompatible ways in future releases.
GNU dialect of-std=c++2c. Support is highly experimental,and will almost certainly change in incompatible ways in futurereleases.
-aux-infofilename ¶Output to the given filename prototyped declarations for all functionsdeclared and/or defined in a translation unit, including those in headerfiles. This option is silently ignored in any language other than C.
Besides declarations, the file indicates, in comments, the origin ofeach declaration (source file and line), whether the declaration wasimplicit, prototyped or unprototyped (‘I’, ‘N’ for new or‘O’ for old, respectively, in the first character after the linenumber and the colon), and whether it came from a declaration or adefinition (‘C’ or ‘F’, respectively, in the followingcharacter). In the case of function definitions, a K&R-style list ofarguments followed by their declarations is also provided, insidecomments, after the declaration.
-fno-asm ¶Do not recognizeasm,inline ortypeof as akeyword, so that code can use these words as identifiers. You can usethe keywords__asm__,__inline__ and__typeof__instead. In C,-ansi implies-fno-asm.
In C++,inline is a standard keyword and is not affected bythis switch. You may want to use the-fno-gnu-keywords flaginstead, which disablestypeof but notasm andinline. In C99 mode (-std=c99 or-std=gnu99),this switch only affects theasm andtypeof keywords,sinceinline is a standard keyword in ISO C99. In C23 mode(-std=c23 or-std=gnu23), this switch only affectstheasm keyword, sincetypeof is a standard keyword inISO C23.
-fno-builtin ¶-fno-builtin-functionDon’t recognize built-in functions that do not begin with‘__builtin_’ as prefix. SeeBuiltins for C Library Functions,for details of the functions affected,including those which are not built-in functions when-ansi or-std options for strict ISO C conformance are used because theydo not have an ISO standard meaning.
GCC normally generates special code to handle certain built-in functionsmore efficiently; for instance, calls toalloca may become singleinstructions which adjust the stack directly, and calls tomemcpymay become inline copy loops. The resulting code is often both smallerand faster, but since the function calls no longer appear as such, youcannot set a breakpoint on those calls, nor can you change the behaviorof the functions by linking with a different library. In addition,when a function is recognized as a built-in function, GCC may useinformation about that function to warn about problems with calls tothat function, or to generate more efficient code, even if theresulting code still contains calls to that function. For example,warnings are given with-Wformat for bad calls toprintf whenprintf is built in andstrlen isknown not to modify global memory.
With the-fno-builtin-function optiononly the built-in functionfunction isdisabled.function must not begin with ‘__builtin_’. If afunction is named that is not built-in in this version of GCC, thisoption is ignored. There is no corresponding-fbuiltin-function option; if you wish to enablebuilt-in functions selectively when using-fno-builtin or-ffreestanding, you may define macros such as:
#define abs(n) __builtin_abs ((n))#define strcpy(d, s) __builtin_strcpy ((d), (s))
-fcond-mismatch ¶Allow conditional expressions with mismatched types in the second andthird arguments. The value of such an expression is void. This optionis not supported for C++.
-ffreestanding ¶Assert that compilation targets a freestanding environment. Thisimplies-fno-builtin. A freestanding environmentis one in which the standard library may not exist, and program startup maynot necessarily be atmain. The most obvious example is an OS kernel.This is equivalent to-fno-hosted.
SeeLanguage Standards Supported by GCC, for details offreestanding and hosted environments.
-fgimple ¶Enable parsing of function definitions marked with__GIMPLE.This is an experimental feature that allows unit testing of GIMPLEpasses.
-fgnu-tm ¶When the option-fgnu-tm is specified, the compilergenerates code for the Linux variant of Intel’s current TransactionalMemory ABI specification document (Revision 1.1, May 6 2009). This isan experimental feature whose interface may change in future versionsof GCC, as the official specification changes. Please note that notall architectures are supported for this feature.
For more information on GCC’s support for transactional memory,SeeThe GNU Transactional Memory Library inGNUTransactional Memory Library.
Note that the transactional memory feature is not supported withnon-call exceptions (-fnon-call-exceptions).
-fgnu89-inline ¶The option-fgnu89-inline tells GCC to use the traditionalGNU semantics forinline functions when in C99 mode.SeeAn Inline Function is As Fast As a Macro.Using this option is roughly equivalent to adding thegnu_inline function attribute to all inline functions(seeDeclaring Attributes of Functions).
The option-fno-gnu89-inline explicitly tells GCC to use theC99 semantics forinline when in C99 or gnu99 mode (i.e., itspecifies the default behavior).This option is not supported in-std=c90 or-std=gnu90 mode.
The preprocessor macros__GNUC_GNU_INLINE__ and__GNUC_STDC_INLINE__ may be used to check which semantics arein effect forinline functions. SeeCommon PredefinedMacros inThe C Preprocessor.
-fhosted ¶Assert that compilation targets a hosted environment. This implies-fbuiltin. A hosted environment is one in which theentire standard library is available, and in whichmain has a returntype ofint. Examples are nearly everything except a kernel.This is equivalent to-fno-freestanding.
-flax-vector-conversions ¶Allow implicit conversions between vectors with differing numbers ofelements and/or incompatible element types. This option should not beused for new code.
-fms-extensions ¶Accept some non-standard constructs used in Microsoft header files.
In C++ code, this allows member names in structures to be similarto previous types declarations.
typedef int UOW;struct ABC { UOW UOW;};Some cases of unnamed fields in structures and unions are onlyaccepted with this option. SeeUnnamed struct/unionfields within structs/unions, for details.
Note that this option is off for all targets except for x86targets using ms-abi.
-fpermitted-flt-eval-methods=style ¶ISO/IEC TS 18661-3 defines new permissible values forFLT_EVAL_METHOD that indicate that operations and constants witha semantic type that is an interchange or extended format should beevaluated to the precision and range of that type. These new values area superset of those permitted under C99/C11, which does not specify themeaning of other positive values ofFLT_EVAL_METHOD. As such, codeconforming to C11 may not have been written expecting the possibility ofthe new values.
-fpermitted-flt-eval-methods specifies whether the compilershould allow only the values ofFLT_EVAL_METHOD specified in C99/C11,or the extended set of values specified in ISO/IEC TS 18661-3.
style is eitherc11 orts-18661-3 as appropriate.
The default when in a standards compliant mode (-std=c11 or similar)is-fpermitted-flt-eval-methods=c11. The default when in a GNUdialect (-std=gnu11 or similar) is-fpermitted-flt-eval-methods=ts-18661-3.
The ‘-fdeps-*’ options are used to extract structured dependencyinformation for a source. This involves determining what resources provided byother source files will be required to compile the source as well as whatresources are provided by the source. This information can be used to addrequired dependencies between compilation rules of dependent sources based ontheir contents rather than requiring such information be reflected within thebuild tools as well.
-fdeps-file=file ¶Where to write structured dependency information.
-fdeps-format=format ¶The format to use for structured dependency information. ‘p1689r5’ is theonly supported format right now. Note that when this argument is specified, theoutput of ‘-MF’ is stripped of some information (namely C++ modules) sothat it does not use extended makefile syntax not understood by most tools.
-fdeps-target=file ¶Analogous to-MT but for structured dependency information. Thisindicates the target which will ultimately need any required resources andprovide any resources extracted from the source that may be required by othersources.
-fplan9-extensions ¶Accept some non-standard constructs used in Plan 9 code.
This enables-fms-extensions, permits passing pointers tostructures with anonymous fields to functions that expect pointers toelements of the type of the field, and permits referring to anonymousfields declared using a typedef. SeeUnnamedstruct/union fields within structs/unions, for details. This is onlysupported for C, not C++.
-fsigned-bitfields ¶-funsigned-bitfields-fno-signed-bitfields-fno-unsigned-bitfieldsThese options control whether a bit-field is signed or unsigned, when thedeclaration does not use eithersigned orunsigned. Bydefault, such a bit-field is signed, because this is consistent: thebasic integer types such asint are signed types.
-fsigned-char ¶Let the typechar be signed, likesigned char.
Note that this is equivalent to-fno-unsigned-char, which isthe negative form of-funsigned-char. Likewise, the option-fno-signed-char is equivalent to-funsigned-char.
-funsigned-char ¶Let the typechar be unsigned, likeunsigned char.
Each kind of machine has a default for whatchar shouldbe. It is either likeunsigned char by default or likesigned char by default.
Ideally, a portable program should always usesigned char orunsigned char when it depends on the signedness of an object.But many programs have been written to use plainchar andexpect it to be signed, or expect it to be unsigned, depending on themachines they were written for. This option, and its inverse, let youmake such a program work with the opposite default.
The typechar is always a distinct type from each ofsigned char orunsigned char, even though its behavioris always just like one of those two.
-fstrict-flex-arrays(C and C++ only) ¶-fstrict-flex-arrays=level(C and C++ only)Control when to treat the trailing array of a structure as a flexible arraymember for the purpose of accessing the elements of such an array. The valueoflevel controls the level of strictness.
-fstrict-flex-arrays is equivalent to-fstrict-flex-arrays=3, which is the strictest;a trailing array is treated as a flexible array member only whenit is declared as a flexible array member per C99 standard onwards.
The negative form-fno-strict-flex-arrays is equivalent to-fstrict-flex-arrays=0, which is the least strict. In thiscase all trailing arrays of structures are treated as flexible array members.
There are two more levels in between 0 and 3, which are provided tosupport older code that uses the GCC zero-length array extension(‘[0]’) or one-element array as flexible array members(‘[1]’). Whenlevel is 1, the trailing array is treated asa flexible array member when it is declared as either ‘[]’,‘[0]’, or ‘[1]’. Whenlevel is 2, the trailing arrayis treated as a flexible array member when it is declared as either‘[]’, or ‘[0]’.
You can control this behavior for a specific trailing array field of astructure by using the variable attributestrict_flex_array attribute(seeSpecifying Attributes of Variables).
The-fstrict_flex_arrays option interacts with the-Wstrict-flex-arrays option. SeeOptions to Request or Suppress Warnings, for moreinformation.
-fsso-struct=endianness ¶Set the default scalar storage order of structures and unions to thespecified endianness. The accepted values are ‘big-endian’,‘little-endian’ and ‘native’ for the native endianness ofthe target (the default). This option is not supported for C++.
Warning: the-fsso-struct switch causes GCC to generatecode that is not binary compatible with code generated without it if thespecified endianness is not the native endianness of the target.
Next:Options Controlling C++ Dialect, Previous:Compiling C++ Programs, Up:GCC Command Options [Contents][Index]