Promotions and Demotions

A type conversion always involves two data items of different types. Whenever possible, QuickC converts the lower-ranking (smaller) data item to the higher-ranking (larger) type. This kind of conversion, called a “promotion,” is normally harmless. For example, since a two-byte int has more than enough room to store a one-byte char, it's generally safe to promote a char value to an int.

Summary: A demotion usually causes a loss of data.

Sometimes, the compiler is forced to convert a higher-ranking value to a lower-ranking type. This kind of conversion, called a “demotion,” usually causes loss of data. For example, the int value 32,000 is much too large to be stored in a char type, which can't hold a number larger than 255. If you assign the value 32,000 to a char variable, some data must be lost.

A demotion of an integer type truncates the higher-ranking type, throwing away the data from high-order bytes that can't fit in the smaller-ranking value. Some demotions of floating-point types round off a value rather than truncate it.