Contents|Index|Previous|Next

Options Controlling C Dialect

The following options control the dialect of C (or languages derived from C, such as C++ and Objective C) that the compiler accepts.

-ansi   
Support all ANSI standard C programs.
This turns off certain features of GNU C that are incompatible with ANSI C, such as the asm, inline and typeof keywords, and predefined macros such as unix and vax that identify the type of system you are using. It also enables the undesirable and rarely used ANSI trigraph feature, disallows the dollar sign symbol ($) as part of identifiers, and disables recognition of C++ style comments with double forward-slash (//).
The alternate keywords, __asm__, __extension__, __inline__ and __typeof__, continue to work despite -ansi. You would not want to use them in an ANSI 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 __unix__ and __vax__, are also available, with or without -ansi.
The -ansi option does not cause non-ANSI programs to be rejected gratuitously. For that, -pedantic is required in addition to -ansi. See also Options to Request or Suppress Warnings. The macro, __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 ANSI standard doesn’t call for; this is to avoid interfering with any programs that might use these names for other things. The functions, alloca, abort, exit, and _exit, are not built-in functions when -ansi is used.
-fno-asm   
Do not recognize asm, inline or typeof as a keyword, so that code can use these words as identifiers. You can use the keywords __asm__, __inline__ and __typeof__ instead. -ansi implies -fno-asm.
In C++, this switch only affects the typeof keyword, since asm and inline are standard keywords. You may want to use the -fno-gnu-keywords flag instead, as it also disables the other, C++-specific, extension keywords such as headof.
-fno-builtin   
Don’t recognize built-in functions that do not begin with two leading underscores. Currently, the functions affected include abort, abs, alloca, cos, exit, fabs, ffs, labs, memcmp, memcpy, sin, sqrt, strcmp, strcpy, and strlen. GCC normally generates special code to handle certain built-in functions more efficiently; for instance, calls to alloca may become single instructions that adjust the stack directly, and calls to 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.
-fhosted
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 main has a return type of int. Examples are nearly everything except a kernel.
This is equivalent to ‘-fno-freestanding’.
-ffreestanding
Assert that compilation takes place in a freestanding envi-ronment. 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’.
The -ansi option prevents alloca and ffs from being built-in functions, since these functions do not have an ANSI standard meaning.
-trigraphs   
Support ANSI C trigraphs. You don’t want to know about this brain-damage.
The -ansi option implies -trigraphs.
-traditional    
Attempt to support some aspects of traditional C compilers. Specifically:
You may wish to use ‘-fno-builtin’ as well as ‘-traditional’ if your program uses names that are normally GNU C builtin functions for other purposes of its own.
You cannot use ‘-traditional’ if you include any header files that rely on ANSI C features. Some vendors are starting to ship systems with ANSI C header files and you cannot use ‘-traditional’ on such systems to compile files that include any system headers.
The ‘-traditional’ option also enables the ‘-traditional-cpp’ option which is described in the following discussion.
-traditional-cpp
Attempt to support some aspects of traditional C preprocessors. Specifically:
You may wish to use ‘-fno-builtin’ as well as ‘-traditional’ if your program uses names that, for other purposes of its own, are normally GNU C built-in functions.
You cannot use ‘-traditional’ if you include any header files that rely on ANSI C features. Some vendors are starting to ship systems with ANSI C header files and you cannot use ‘-traditional’ on such systems to compile files that include any system headers.
-traditional-cpp   
Attempt to support some aspects of traditional C preprocessors. This includes the last five items in the previous descriptions, but none of the other effects of ‘-traditional’.
-fcond-mismatch   
Allow conditional expressions with mismatched types in the second and third arguments.
The value of such an expression is void.
-funsigned-char   
Let the type char be unsigned, like unsigned char.
Each kind of machine has a default for what char should be. It is either like unsigned char by default or like signed char by default.
Ideally, a portable program should always use signed char or unsigned char when it depends on the signedness of an object. But many programs have been written to use plain char and expect it to be signed, or expect it to be unsigned, depending on the machines for which they were written. This option, and its inverse, let you make such a program work with the opposite default.
The type char is always a distinct type from each of signed char or unsigned char, even though its behavior is always just like one of those two dialect options.
-fsigned-char    
Let the type char be signed, like signed char.
You may wish to use ‘-fno-builtin’ as well as ‘-traditional’ if your program uses names that are normally GNU C builtin functions for other purposes of its own.
You cannot use ‘-traditional’ if you include any header files that rely on ANSI C features. Some vendors are starting to ship systems with ANSI C header files and you cannot use ‘-traditional’ on such systems to compile files that include any system headers.
-fsigned-bitfields    
-funsigned-bitfields
-fno-signed-bitfields
-fno-unsigned-bitfields
These options control whether a bitfield is signed or unsigned, when the declaration does not use either signed or unsigned. By default, such a bitfield is signed, because this is consistent: the basic integer types such as int are signed types. However, when ‘-traditional’ is used, bitfields are all unsigned no matter what.
-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. The ‘-traditional’ option also has this effect.
Writing into string constants is a very bad idea; constants should be constant.
-fallow-single-precision   
Do not promote single precision math operations to double precision, even when compiling with ‘-traditional’.
Traditional K&R C promotes all floating point operations to double precision, regardless of the sizes of the operands. On the architecture for which you are compiling, single precision may be faster than double precision. If you must use ‘-traditional’, but want to use single precision operations when the operands are single precision, use this option. This option has no effect when compiling with ANSI or GNU C conventions (the default).