In accordance with the different language standards defined for C, the compiler supports five C compilation modes:
K&R C mode (POSIX option -X kr, SDF option MODE=KERNIGHAN-RITCHIE)
The compiler accepts C code based on the language definition by Kernighan & Ritchie as well as some ANSI-specific extensions.
Extended C89 mode (POSIX option -X 1990 -X nostrict, SDF option MODE=1990, STRICT=NO)
The compiler accepts C code based on the ANSI C89 definition resp. the ISO C standard from 1990 (including ISO C Amendments 1) in extended mode.
Strict C89 mode (POSIX option -X 1990 -X strict, SDF option MODE=1990, STRICT=YES)
The compiler accepts C code based on the ANSI C89 definition resp. the ISO C standard from 1990 (including ISO C Amendments 1) in strict mode.
Extended C11 mode (POSIX option -X 2011 -X nostrict, SDF option MODE=2011, STRICT=NO)
The compiler accepts C code based on the ISO C standard from 2011 in extended mode.
Strict C11 mode (POSIX option -X 2011 -X strict, SDF option MODE=2011, STRICT=YES)
The compiler accepts C code based on the ISO C standard from 2011 in strict mode.
The following table contains an overview of the language elements defined in the ANSI/ISO C standard and indicates which of those elements are supported in the language modes modes.
Key to the entries in the table:
X | Fully supported in strict and extended language mode |
o | Supported syntactically, but not semantically |
- | Not supported |
Lexical elements
C language elements | Language definition | Compilation mode | ||||
C11 | C89 | K&R | C11 | C89 | K&R | |
Multibyte characters | X | X |
| X | X | X |
Trigraph sequences
| X | X |
| X | X | X |
Digraph sequences 1)
| X | X |
| X | X | X |
Escape sequences | ||||||
| X | X | - | X | X | - |
| X | X | X | X | X | X |
| - | - | - | X | X | X |
| X | X | X | X | X | X |
| X | X | X | X | X | X |
| X | X | X | X | X | X |
| X | X | X | X | X | X |
| X | X | - | X | X | X |
| X | X | X | X | X | X |
| X | X | - | X | X | X |
| X | X | - | X | X | X |
| X | X | X | X | X | X |
\ octdigits | X | X | X | X | X | X |
\u decdigits \U decdigits | X | - | - | X | - | - |
\x hexdigits | X | X | - | X | X | X |
Lengths of identifiers | ||||||
internal | 63 | 31 | 8 | all characters are significant | ||
external | 31 | 6 | <8 | 30/32/32K 2) | ||
Keywords 3) | ||||||
Constants | ||||||
integer | X | X | X | X | X | X |
float | X | X | X | X | X | X |
character | X | X | X | X | X | X |
L'character' | X | X | - | X | X | X |
u'character' U'character' | X | - | - | X | - | - |
string | X | X | X | X | X | X |
L"string" | X | X | - | X | X | X |
u"string" U"string" | X | - | - | X | - | - |
enum | X | X | X | X | X | X |
Suffixes | ||||||
integer L,l | X | X | X | X | X | X |
integer U, u | X | X | - | X | X | X |
integer LL, ll | X | - | - | X | X | X |
float F, f | X | X | - | X | X | X |
float L,l | X | X | - | X | X | X |
Notes
1) Digraph sequences
Digraph sequences are defined in the ISO C Amendment 1 and are recognized in the C compilation modes only if the POSIX option -K alternative_tokens
or the SDF option ALTERNATIVE-TOKENS=*YES is set. In language mode C11 thea are activated by default.
2) Length of external names
For more information see "Implementation-defined behavior based on the ANSI/ISO C standard", sub-item "Identifiers".
3) Reserved keywords
asm | continue | extern | int | signed | union |
auto | default | float | long | sizeof | unsigned |
break | do | for | register | static | void |
case | double | goto | restrict | struct | volatile |
char | else | if | return | switch | while |
const | enum | inline | short | typedef |
The asm
keyword is reserved in K&R mode and in extended C mode. However, since the inline substitution of Assembler code is not yet supported, the use of this keyword will result in an error. The asm
keyword is not reserved in the strict C mode.
The inline
and restrict
keywords are only defined and available in mode C11.
Data type declarations
C language elements | Language definition | Compilation mode | ||||
C11 | C89 | K&R | C11 | C89 | K&R | |
Type specifiers | ||||||
void 1) | X | X | - | X | X | X |
void * 1) | X | X | - | X | X | X |
char | X | X | X | X | X | X |
short | X | X | X | X | X | X |
int | X | X | X | X | X | X |
long | X | X | X | X | X | X |
long long | X | - | - | X | X | X |
float | X | X | X | X | X | X |
double | X | X | X | X | X | X |
long double | X | X | - | X | X | X |
signed | X | X | - | X | X | X |
unsigned | X | X | X | X | X | X |
array [ ] | X | X | X | X | X | X |
structure 2) | X | X | X | X | X | X |
union 2) | X | X | X | X | X | X |
(*) | X | X | X | X | X | X |
enum | X | X | X | X | X | X |
() | X | X | X | X | X | X |
Type qualifiers | ||||||
const | X | X | - | X | X | o |
volatile | X | X | - | X | X | o |
Initialization | ||||||
auto aggregate | X | X | - | X | X | X |
Storage classes | ||||||
typedef | X | X | X | X | X | X |
extern | X | X | X | X | X | X |
static | X | X | X | X | X | X |
auto | X | X | X | X | X | X |
register | X | X | X | X | X | X |
Bitfield types | ||||||
int | X | X | X | X | X | X |
signed int | X | X | X | X | X | X |
_Bool | X | - | - | X | X | X |
all integral | - | - | - | X | X | X |
Data type declarations
Notes
1) void
The type void
signifies an empty set of values. It can be used in the following three ways:
Result type of functions which do not return a value.
A pointer to void points to an object of any data type.
The number of parameters and the data types of the parameters can be specified in a function declaration (see Prototyping). If
void
is used instead of the parameter list, then the function has no parameters.
2) structure, union
In accordance with ANSI C, structures and unions may be mutually assigned (if of the same type), passed to functions as parameters, and returned as exit values of functions.
These options are also supported in K&R mode.
Conversion rules
C language elements | Language definition | Compilation mode | ||||
C11 | C89 | K&R | C11 | C89 | K&R | |
value preserving | X | X |
| X | X |
|
sign preserving |
|
| X |
|
| X |
Conversion rules
One important difference between ANSI and K&R lies in the area of implicit arithmetic conversions.
In K&R C, operands of an expression are converted using the “unsigned preserving” rule, i.e. extending an operand of type unsigned char
or unsigned short
produces a result of type unsigned int
. If unsigned
types appear in an expression together with other types, the result is always unsigned
.
In ANSI C, by contrast, the “value-preserving” rule applies, i.e. the result type depends on the size of the operand type. Extending an operand of type unsigned char
or unsigned short
thus produces a result of type int
if int
is large enough to represent all values of the smaller type. Otherwise, the result is an unsigned int
.
Due to this difference, the results of arithmetic expressions could differ in some cases and thus lead to different program behavior. This must be taken into account when moving from K&R C to ANSI C.
Functions
C language elements | Language definition | Compilation mode | ||||
C11 | C89 | K&R | C11 | C89 | K&R | |
Definition "old“ 1) | X | X | X | X | X | X |
Definition "new“ | X | X |
| X | X | X |
Prototyping 2) | X | X |
| X | X | o |
Parameter type matching 3) | X | X |
| X | X |
|
Notes
1) Definition of functions
In contrast to K&R, ANSI has introduced a new syntax for the definition of formal function parameters, but also allows the “old-style” (K&R) syntax.
Both definition types are also supported in K&R mode.
2) Prototyping
In contrast to K&R, ANSI defines function prototypes. These are function declarations in which the number and types of individual parameters are also specified. This enables the compiler to compare the types of current parameters with those of formal parameters in the declaration and to adapt them to the formal parameters as required.
Prototype declarations are syntactically allowed in K&R mode, but have no semantic significance
3) Parameter type matching
The advantage of prototyping is that the parameters specified in the function declaration are not subject to standard conversion rules. A parameter that is declared there as float
will also be passed as float
, without first being converted to double
. If K&R and ANSI objects are to be combined, floating-point parameters should always be declared double
.
The automatic matching of parameter types is not supported in K&R mode.
Preprocessor directives
C language elements | Language definition | Compilation mode | ||||
C11 | C89 | K&R | C11 | C89 | K&R | |
# (stringizing) | X | X |
| X | X | X |
## (token pasting) | X | X |
| X | X | X |
#assert / #unassert |
|
|
| X | X | X |
#define | X | X | X | X | X | X |
defined | X | X |
| X | X | X |
#elif | X | X |
| X | X | X |
#else | X | X | X | X | X | X |
#endif | X | X | X | X | X | X |
#error | X | X |
| X | X | X |
#include | X | X | X | X | X | X |
#if | X | X | X | X | X | X |
#ifdef | X | X | X | X | X | X |
#ifndef | X | X | X | X | X | X |
#ident |
|
|
| o | o | o |
#line | X | X | X | X | X | X |
#line (old style) |
|
| X | X | X | X |
#pragma | X | X |
| X | X | X |
#pragma STDC | X |
|
| o | o | o |
#undef | X | X | X | X | X | X |
# (null directive) | X | X |
| X | X | X |
Preprocessor directives
Predefined macro names
C language elements | Language definition | Compilation mode | ||||
C11 | C89 | K&R | C11 | C89 | K&R | |
| X | X |
| X | X | X |
| X | X | - | X | X | X |
| X | X | - | X | X | X |
| X | X | - | X | X | X |
| X | X | - | X | X | X |
| X | X | - | X | X | - |
Predefined macro names
Notes
1) __STDC_VERSION__
For more information see "Predefined preprocessor names".