DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
C language compilers

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 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 previous System V 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) mode will the compiler use the unsigned preserving promotions; in the other two modes, conformance (-Xc) and ANSI (-Xa), the value preserving promotion rules will be used. If you use the -v option to the cc command, the compiler will warn about each expression whose behavior might depend on the promotion rules used.


Next topic: Phases of translation
Previous topic: Feature test macros

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004