C language compiler

Compilation modes

The compilation system has five compilation modes that correspond to degrees of compliance with ANSI C. The modes are:

Extended ANSI C (the default). This specifies ANSI and ISO C standards conformance except that some required warnings are omitted and the name space is expanded to include names that are not specified by the standards. All C language constructions behave as specified in the standards. All implemented language extensions beyond the standards are also available.

Conformant ANSI and ISO C. This is a strict standards conforming C compiler satisfying the language specification in all respects, including issuing all necessary diagnostics for illegal programs. Certain extensions (such as the asm keyword) are not available in this dialect.

The ``classic'' C, or the dialect compatible with K&R C (See The C Programming Language, Kernighan and Ritchie, First Edition).

A Microsoft C compiler compatibility mode. This is equivalent to option -Xa, plus some (but not all) language extensions provided in older releases of the native SCO OpenServer C compiler, which was derived from Microsoft C compiler version 6. gn particular, some Intel® specific keywords like near and far are supported. This is intended as a transitional aid and may not be supported in future releases.

A ``transitional mode'' between K&R and ANSI C. This specifies ANSI and ISO C standards conformance except where the semantics differ from classic C. In addition, warnings are issued about preprocessing phase semantic changes such as new escape sequences (like \x) and any trigraph replacements (like ??!). Certain potential optimizations available in the other -X modes are also disabled.

Global behavior

A program that depends on unsigned-preserving arithmetic conversions will behave differently. This is considered to be the most serious change made by ANSI C to a widespread current practice.

In The C Programming Language, Kernighan and Ritchie, (First Edition), unsigned specified exactly one type; there were no unsigned chars, unsigned shorts, or unsigned longs, but most C compilers added these very soon thereafter.

In many pre-ANSI C compilers, the ``unsigned-preserving'' rule is used for promotions: when an unsigned type needs to be widened, it is widened to an unsigned type; when an unsigned type mixes with a signed type, the result is an unsigned type.

The other rule, specified by ANSI C, came to be called ``value-preserving,'' in which the result type depends on the relative sizes of the operand types. When an unsigned char or unsigned short is ``widened,'' the result type is int if an int is large enough to represent all the values of the smaller type. Otherwise the result type would be unsigned int. The ``value-preserving'' rule produces the ``least surprise'' arithmetic result for most expressions.

Only in the transition (-Xt) or classic (-Xk) mode will the compiler use the unsigned-preserving promotions; in the other three modes, -Xc, -Xa and -Xm, the value-preserving promotion rules will be used. No matter what the current mode may be, the compiler can warn about each expression whose behavior might depend on the promotion rules used.

This warning is given if the warning level is 2 (-w2) or 3 (-w2).

Next topic: Phases of translation
Previous topic: C language compiler

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003