OPTIMIZATIONS
Function
None
None
__CNI__
None
Enhances code density of character operations by omitting integral promotion. This option enables a non
ANSI-C compliant behavior.
In ANSI-C operations with data types, anything smaller than int must be promoted to int (integral promotion). With this rule, adding two unsigned character variables results in a zero-extension of each character operand, and then adding them back in as int operands. If the result must be stored back into a character, this integral promotion is not necessary. When this option is set, promotion is avoided where possible.
The code size may be decreased if this option is set because operations may be performed on a character base instead of an integer base.
The -Cni option enhances character operation code density by omitting integral promotion.
Consider the following:
- In most expressions,
ANSI-C requires char type variables to be extended to the next larger type int, which is required to be at least 16-bit in size by the ANSI standard.
- The -Cni option suppresses this ANSI-C behavior and thus allows 'characters' and 'character sized constants' to be used in expressions. This option does not conform to ANSI standards. Code compiled with this option is not portable.
- The ANSI standard requires that 'old style declarations' of functions using the char parameter, as shown in the below listing, be extended to int. The -Cni option disables this extension and saves additional RAM.
See the following listing for an example of "no integer promotion."
Listing: Definition of an `old style function' using a char parameter.
old_style_func (a, b, c)
char a, b, c;
{
...
}
The space reserved for a, b, and c is just one byte each, instead of two.
For expressions containing different types of variables, the following conversion rules apply:
- If both variables are of type signed char, the expression is evaluated signed.
- If one of two variables is of type unsigned char, the expression is evaluated unsigned, regardless of whether the other variable is of type signed or unsigned char.
- If one operand is of another type than signed or unsigned char, the usual ANSI-C arithmetic conversions are applied.
- If constants are in the character range, they are treated as characters. Remember that the char type is signed and applies to the constants -128 to 127. All constants greater than 127, (i.e., 128, 129, etc.) are treated as integer. If you want them treated as characters, they must be cast (refer to the following listing).
Listing: Casting integers to signed char
signed char a, b;
if (a > b * (signed char)129)
Note:
This option is ignored with the -Ansi Compiler switch active.
Note:
With this option set, the code that is generated does not conform to the ANSI standard. In other words: the code generated is wrong if you apply the ANSI standard as reference. Using this option is not recommended in most cases.