📄 invoke.texi
字号:
@node C Dialect Options@section Options Controlling C Dialect@cindex dialect options@cindex language dialect options@cindex options, dialectThe following options control the dialect of C (or languages derivedfrom C, such as C++, Objective-C and Objective-C++) that the compileraccepts:@table @gcctabopt@cindex ANSI support@cindex ISO support@item -ansi@opindex ansiIn C mode, this is equivalent to @samp{-std=c89}. In C++ mode, it isequivalent to @samp{-std=c++98}.This turns off certain features of GCC that are incompatible with ISOC90 (when compiling C code), or of standard C++ (when compiling C++ code),such as the @code{asm} and @code{typeof} keywords, andpredefined macros such as @code{unix} and @code{vax} that identify thetype of system you are using. It also enables the undesirable andrarely used ISO trigraph feature. For the C compiler,it disables recognition of C++ style @samp{//} comments as well asthe @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, ofcourse, but it is useful to put them in header files that might be includedin compilations done with @option{-ansi}. Alternate predefined macrossuch as @code{__unix__} and @code{__vax__} are also available, with orwithout @option{-ansi}.The @option{-ansi} option does not cause non-ISO programs to berejected gratuitously. For that, @option{-pedantic} is required inaddition 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 refrainfrom declaring certain functions or defining certain macros that theISO standard doesn't call for; this is to avoid interfering with anyprograms that might use these names for other things.Functions that would normally be built in but do not have semanticsdefined by ISO C (such as @code{alloca} and @code{ffs}) are not built-infunctions when @option{-ansi} is used. @xref{Other Builtins,,Otherbuilt-in functions provided by GCC}, for details of the functionsaffected.@item -std=@opindex stdDetermine the language standard. @xref{Standards,,Language 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 @samp{c89} or@samp{c++98}, and GNU dialects of those standards, such as@samp{gnu89} or @samp{gnu++98}. By specifing a base standard, thecompiler will accept all programs following that standard and thoseusing GNU extensions that do not contradict it. For example,@samp{-std=c89} turns off certain features of GCC that areincompatible with ISO C90, such as the @code{asm} and @code{typeof}keywords, but not other GNU extensions that do not have a meaning inISO C90, such as omitting the middle term of a @code{?:}expression. On the other hand, by specifing a GNU dialect of astandard, all features the compiler support are enabled, even whenthose features change the meaning of the base standard and somestrict-conforming programs may be rejected. The particular standardis used by @option{-pedantic} to identify which features are GNUextensions given that version of the standard. For example@samp{-std=gnu89 -pedantic} would warn about C++ style @samp{//}comments, while @samp{-std=gnu99 -pedantic} would not.A value for this option must be provided; possible values are@table @samp@item c89@itemx iso9899:1990Support all ISO C90 programs (certain GNU extensions that conflictwith ISO C90 are disabled). Same as @option{-ansi} for C code.@item iso9899:199409ISO C90 as modified in amendment 1.@item c99@itemx c9x@itemx iso9899:1999@itemx iso9899:199xISO C99. Note that this standard is not yet fully supported; see@w{@uref{http://gcc.gnu.org/gcc-4.3/c99status.html}} for more information. Thenames @samp{c9x} and @samp{iso9899:199x} are deprecated.@item gnu89GNU dialect of ISO C90 (including some C99 features). Thisis the default for C code.@item gnu99@itemx gnu9xGNU dialect of ISO C99. When ISO C99 is fully implemented in GCC,this will become the default. The name @samp{gnu9x} is deprecated.@item c++98The 1998 ISO C++ standard plus amendments. Same as @option{-ansi} forC++ code.@item gnu++98GNU dialect of @option{-std=c++98}. This is the default forC++ code.@item c++0xThe working draft of the upcoming ISO C++0x standard. This optionenables experimental features that are likely to be included inC++0x. The working draft is constantly changing, and any feature that isenabled by this flag may be removed from future versions of GCC if it isnot part of the C++0x standard.@item gnu++0xGNU dialect of @option{-std=c++0x}. This option enablesexperimental features that may be removed in future versions of GCC.@end table@item -fgnu89-inline@opindex fgnu89-inlineThe option @option{-fgnu89-inline} tells GCC to use the traditionalGNU semantics for @code{inline} functions when in C99 mode.@xref{Inline,,An Inline Function is As Fast As a Macro}. This optionis accepted and ignored by GCC versions 4.1.3 up to but not including4.3. In GCC versions 4.3 and later it changes the behavior of GCC inC99 mode. Using this option is roughly equivalent to adding the@code{gnu_inline} function attribute to all inline functions(@pxref{Function Attributes}).The option @option{-fno-gnu89-inline} explicitly tells GCC to use theC99 semantics for @code{inline} when in C99 or gnu99 mode (i.e., itspecifies the default behavior). This option was first supported inGCC 4.3. This option is not supported in C89 or gnu89 mode.The preprocessor macros @code{__GNUC_GNU_INLINE__} and@code{__GNUC_STDC_INLINE__} may be used to check which semantics arein effect for @code{inline} functions. @xref{Common PredefinedMacros,,,cpp,The C Preprocessor}.@item -aux-info @var{filename}@opindex aux-infoOutput 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 (@samp{I}, @samp{N} for new or@samp{O} for old, respectively, in the first character after the linenumber and the colon), and whether it came from a declaration or adefinition (@samp{C} or @samp{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.@item -fno-asm@opindex fno-asmDo not recognize @code{asm}, @code{inline} or @code{typeof} as akeyword, so that code can use these words as identifiers. You can usethe 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 touse the @option{-fno-gnu-keywords} flag instead, which has the sameeffect. In C99 mode (@option{-std=c99} or @option{-std=gnu99}), thisswitch 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 functionsDon't recognize built-in functions that do not begin with@samp{__builtin_} as prefix. @xref{Other Builtins,,Other built-infunctions 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 theydo not have an ISO standard meaning.GCC normally generates special code to handle certain built-in functionsmore efficiently; for instance, calls to @code{alloca} may become singleinstructions that adjust the stack directly, and calls to @code{memcpy}may 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 @option{-Wformat} for bad calls to@code{printf}, when @code{printf} is built in, and @code{strlen} isknown not to modify global memory.With the @option{-fno-builtin-@var{function}} optiononly the built-in function @var{function} isdisabled. @var{function} must not begin with @samp{__builtin_}. If afunction is named this is not built-in in this version of GCC, thisoption is ignored. There is no corresponding@option{-fbuiltin-@var{function}} option; if you wish to enablebuilt-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 environmentAssert that compilation takes place in a hosted environment. This implies@option{-fbuiltin}. A hosted environment is one in which theentire standard library is available, and in which @code{main} has a returntype of @code{int}. Examples are nearly everything except a kernel.This is equivalent to @option{-fno-freestanding}.@item -ffreestanding@opindex ffreestanding@cindex hosted environmentAssert that compilation takes place in a freestanding environment. Thisimplies @option{-fno-builtin}. A freestanding environmentis one in which the standard library may not exist, and program startup maynot 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 offreestanding and hosted environments.@item -fopenmp@opindex fopenmp@cindex openmp parallelEnable handling of OpenMP directives @code{#pragma omp} in C/C++ and@code{!$omp} in Fortran. When @option{-fopenmp} is specified, thecompiler generates parallel code according to the OpenMP ApplicationProgram Interface v2.5 @w{@uref{http://www.openmp.org/}}. This optionimplies @option{-pthread}, and thus is only supported on targets thathave support for @option{-pthread}.@item -fms-extensions@opindex fms-extensionsAccept some non-standard constructs used in Microsoft header files.Some cases of unnamed fields in structures and unions are onlyaccepted with this option. @xref{Unnamed Fields,,Unnamed struct/unionfields within structs/unions}, for details.@item -trigraphs@opindex trigraphsSupport 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-cppPerforms a compilation in two passes: preprocessing and compiling. Thisoption allows a user supplied "cc1", "cc1plus", or "cc1obj" via the@option{-B} option. The user supplied compilation step can then add inan additional preprocessing step after normal preprocessing but beforecompiling. 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 traditionalFormerly, these options caused GCC to attempt to emulate a pre-standardC compiler. They are now only supported with the @option{-E} switch.The preprocessor continues to support a pre-standard mode. See the GNUCPP manual for details.@item -fcond-mismatch@opindex fcond-mismatchAllow conditional expressions with mismatched types in the second andthird arguments. The value of such an expression is void. This optionis not supported for C++.@item -flax-vector-conversions@opindex flax-vector-conversionsAllow implicit conversions between vectors with differing numbers ofelements and/or incompatible element types. This option should not beused for new code.@item -funsigned-char@opindex funsigned-charLet the type @code{char} be unsigned, like @code{unsigned char}.Each kind of machine has a default for what @code{char} shouldbe. 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} 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 type @code{char} is always a distinct type from each of@code{signed char} or @code{unsigned char}, even though its behavioris always just like one of those two.@item -fsigned-char@opindex fsigned-charLet the type @code{char} be signed, like @code{signed char}.Note
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -