4.3 Common C Interface

The Common C Interface (CCI) is available with all MPLAB XC C compilers and is designed to enhance code portability between these compilers by standardizing implementation-defined behavior and non-standard extensions. Several features available for AVR targets when using MPLAB XC8 are available only when the CCI is enabled.

The CCI can be enforced by using the -mext=cci option. There is a checkbox for this option (“Use CCI syntax”) found in the “Preprocessing and messaging” options, within the “XC8 Compiler” category in the MPLAB X IDE Project Properties for your project. When enabled, C source code is verified to ensure it is compliant with CCI. Many of the features require that the generic header <xc.h> be included; however this is typically included with MPLAB XC compiler projects anyway, to allow access to device special function registers and resource (see Headers for Device-specific Resources).

When the CCI is enabled, the signedness of a plain char type is made unsigned, whereas it is signed if no pertinent option is specified.

The following macros are available when the CCI is enabled and replace the use of similar attributes.

__align(n)
Align the object’s address with the next n-byte boundary.
__deprecate
Generate a warning whenever the specified object is used.
__pack
Force the object or structure member to have the smallest possible alignment.
__persistent
Do not clear the object at startup.
__section(section)
Allocate the object to a user-nominated section.
__at(address)
Place the object at the specified address.
__interrupt()
Define an interrupt function.
For example, with the CCI enabled, the following code is valid:
#include <xc.h>

const int settings[] __at(0x260) = { 22, 5 }; //place at Flash location 0x260
int ramloc[6] __at(0x800150);                 //place at RAM location 0x150

/* SPI interrupt code */
void __interrupt(SPI_STC_vect_num) spi_Isr(void) { 
  process(SPI_ClientReceive());
  return;
}