3.4 Options Controlling C Dialect
The following options control the dialect of C (or languages derived from C, such as C++, Objective-C and Objective-C++) that the compiler accepts:
- 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
typeofkeywords, and predefined macros such as
vaxthat 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 `//' comments as well as the
The alternate keywords
__typeof__continue to work despite -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 -ansi. Alternate predefined macros such as
__vax__are also available, with or without -ansi.
The -ansi option does not cause non-ISO programs to be rejected gratuitously. For that, -pedantic is required in addition to -ansi. See Warning Options.
__STRICT_ANSI__is predefined when the -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
ffs) are not built-in functions with -ansi is used. See Other built-in functions provided by GCC, for details of the functions affected.
- 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
- ISO C90 (same as -ansi).
- ISO C90 as modified in amendment 1.
- ISO C99. Note that this standard is not yet fully supported; see
http://gcc.gnu.org/gcc-4.2/c99status.html for more information. The
names `c9x' and `iso9899:199x' are deprecated.
- Default, ISO C90 plus GNU extensions (including some C99 features).
- ISO C99 plus GNU extensions. When ISO C99 is fully implemented in GCC,
this will become the default. The name `gnu9x' is deprecated.
- The 1998 ISO C++ standard plus amendments.
- The same as -std=c++98 plus GNU extensions. This is the default for C++ code.
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
__restrict__even when -std=c99 is not specified.
The -std options specifying some version of ISO C have the same effects as -ansi, except that features that were not in ISO C90 but are in the specified version (for example, `//' comments and the
inlinekeyword in ISO C99) are not disabled.
See Language Standards Supported by GCC, for details of these standard versions.
- The option -fgnu89-inline tells GCC to use the traditional
GNU semantics for
inlinefunctions when in C99 mode. See An Inline Function is As Fast As a Macro. Using this option is roughly equivalent to adding the
gnu_inlinefunction attribute to all inline functions (see Function Attributes).
This option is accepted by GCC versions 4.1.3 and up. In GCC versions /* APPLE LOCAL extern inline */ prior to 4.3 (4.2 for Apple's gcc), C99 inline semantics are not supported, and thus this option is effectively assumed to be present regardless of whether or not it is specified; the only effect of specifying it explicitly is to disable warnings about using inline functions in C99 mode. Likewise, the option -fno-gnu89-inline is not supported in versions of /* APPLE LOCAL extern inline */ GCC before 4.3 (4.2 for Apple's gcc). It is supported only in C99 or gnu99 mode, not in C89 or gnu89 mode.
The preprocesor macros
__GNUC_STDC_INLINE__may be used to check which semantics are in effect for
inlinefunctions. See Common Predefined Macros.
- 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 (`I', `N' for new or `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 (`C' or `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.
- This flag is provided for compatibility with Metrowerks CodeWarrior and MrC
compilers as well as previous Apple versions of GCC. It causes the
-mpim-altivec option to be turned on.
- Enable the use of blocks and entire functions of assembly code within
a C or C++ file. The syntax follows that used in CodeWarrior. (APPLE
- Do not recognize
typeofas a keyword, so that code can use these words as identifiers. You can use the keywords
__typeof__instead. -ansi implies -fno-asm.
In C++, this switch only affects the
inlineare standard keywords. You may want to use the -fno-gnu-keywords flag instead, which has the same effect. In C99 mode (-std=c99 or -std=gnu99), this switch only affects the
inlineis a standard keyword in ISO C99.
- Don't recognize built-in functions that do not begin with
`__builtin_' as prefix. See Other built-in functions provided by GCC, 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 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
allocamay become single instructions that adjust the stack directly, and calls to
memcpymay 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. In addition, when a function is recognized as a built-in function, GCC may use information about that function to warn about problems with calls to that function, or to generate more efficient code, even if the resulting code still contains calls to that function. For example, warnings are given with -Wformat for bad calls to
printfis built in, and
strlenis known not to modify global memory.
With the -fno-builtin-function option only the built-in function function is disabled. function must not begin with `__builtin_'. If a function is named this is not built-in in this version of GCC, this option is ignored. There is no corresponding -fbuiltin-function option; if you wish to enable built-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))
Assert that compilation takes place in a hosted environment. This implies
-fbuiltin. A hosted environment is one in which the
entire standard library is available, and in which
mainhas a return type of
int. Examples are nearly everything except a kernel. This is equivalent to -fno-freestanding.
Assert that compilation takes place in a freestanding environment. This
implies -fno-builtin. A freestanding environment
is one in which the standard library may not exist, and program startup may
not necessarily be at
main. The most obvious example is an OS kernel. This is equivalent to -fno-hosted.
See Language Standards Supported by GCC, for details of freestanding and hosted environments.
- Enable handling of OpenMP directives
#pragma ompin C/C++ and
!$ompin Fortran. When -fopenmp is specified, the compiler generates parallel code according to the OpenMP Application Program Interface v2.5 http://www.openmp.org/.
- Accept some non-standard constructs used in Microsoft header files.
Some cases of unnamed fields in structures and unions are only accepted with this option. See Unnamed struct/union fields within structs/unions, for details.
- Support ISO C trigraphs. The -ansi option (and -std
options for strict ISO C conformance) implies -trigraphs.
- Performs a compilation in two passes: preprocessing and compiling. This
option allows a user supplied "cc1", "cc1plus", or "cc1obj" via the
-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.
- Formerly, these options caused GCC to attempt to emulate a pre-standard
C compiler. They are now only supported with the -E switch.
The preprocessor continues to support a pre-standard mode. See the GNU
CPP manual for details.
- 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++.
- Disable nested functions. This option is not supported for C++ or
Objective-C++. On Darwin, nested functions are disabled by default.
- Enable PCH processing even when -E or -save-temps is used.
- C and C++ forbid the use of casts and conditional expressions as lvalues, e.g.:
float *p, q, r; ((int *)p)++; (cond ? q : r) = 3.0;
As a transitional measure, the Apple version of GCC 4.0 allows casts and conditional expressions to be used as lvalues in certain situations. This is accomplished via the -fnon-lvalue-assign switch, which is on by default. Whenever an lvalue cast or an lvalue conditional expression is encountered, the compiler will issue a deprecation warning and then rewrite the expression as follows:
(type)expr ---becomes---> *(type *)&expr cond ? expr1 : expr2 ---becomes---> *(cond ? &expr1 : &expr2)
To disallow lvalue casts and lvalue conditional expressions altogether, specify -fno-non-lvalue-assign; lvalue casts and lvalue conditional expressions will be disallowed in future versions of Apple's GCC.
- Let the type
charbe unsigned, like
Each kind of machine has a default for what
charshould be. It is either like
unsigned charby default or like
signed charby default.
Ideally, a portable program should always use
unsigned charwhen it depends on the signedness of an object. But many programs have been written to use plain
charand 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.
charis always a distinct type from each of
unsigned char, even though its behavior is always just like one of those two.
- Let the type
charbe signed, like
Note that this is equivalent to -fno-unsigned-char, which is the negative form of -funsigned-char. Likewise, the option -fno-signed-char is equivalent to -funsigned-char.
- These options control whether a bit-field is signed or unsigned, when the
declaration does not use either
unsigned. By default, such a bit-field is signed, because this is consistent: the basic integer types such as
intare signed types.
- Enable the automatic creation of a CoreFoundation-type constant string
whenever a special builtin
__builtin__CFStringMakeConstantStringis called on a literal string. (APPLE ONLY)
- Warn if constant CFString objects contain non-portable characters
- 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.