-Cni: No Integral Promotion on Characters

Group

OPTIMIZATIONS

Scope

Function

Syntax
  -Cni 
  
Arguments

None

Default

None

Defines

__CNI__

Pragmas

None

Description

The -Cni option enhances character operation code density by omitting integral promotion. This option enables behavior that is not ANSI-C compliant.

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 causes the Compiler to zero-extend each character operand, and add them as int operands. Integral promotion is unnecessary when the result will be stored as a character. Using this option, the Compiler avoids promotion when possible. Performing operations on a character base instead of an integer base may decrease code size.

In most expressions, ANSI-C requires char type variables to be extended to the next larger type int, which requires a 16-bit size, according to ANSI standard. The -Cni option suppresses this ANSI-C behavior and thus allows the use of 'characters' and 'character-sized constants' in expressions.

Note: Code generated with this option set does not conform to ANSI standards. Code compiled with this option is not portable. Using this option is not recommended in most cases.

The ANSI standard requires that old-style function declarations using the char parameter be extended to int. The -Cni option disables this extension and saves additional RAM.

Example

Refer the following listing.

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 one byte each, instead of two.

For expressions containing different types of variables, the following conversion rules apply: