What's New in MPLAB® XC8 v2.0

For those who are upgrading their MPLAB® XC8 C Compiler to the new 2.0 version, here is a summary of what is new and what has changed.

New Features

There are a number of new features in the compiler. The following are the more significant additions.

Top-level Driver

A top-level driver is available to allow you to more freely migrate between MPLAB XC compilers. The driver is called xc8-cc and can be used to build for all 8-bit target devices. This driver is automatically used by the MPLAB X IDE for projects that use the new 2.0 XC8 compiler. For users who build on the command line or who use makefiles, new GCC-style options are used with the new driver to control the compiler. The old xc8 compiler driver is still available if required.

C99 Compliance

You may now build projects that conform to most aspects of the C99 C standard. Specific features and limitations associated with this change are detailed in a later section of this article. You can choose to have code compiled to the C90 standard (as was the case with earlier compiler versions) if desired.

Front End

The compiler’s C99 compliance is in part implemented through the Clang compiler front end. Clang is now used by default, and this application and C99 compliance go hand-in-hand. Clang replaces the C preprocessor and parser (CPP and P1 applications) used by previous compiler versions, although these applications are still shipped and are always used whenever you code for C90. Clang’s source code parsing is more sophisticated than that of the previous parser, so if you swap an existing project over to use C99, you might see new or different warning messages when building.

Libraries

New C99-compliant libraries are provided with the compiler. These libraries are based on the musl libc and provide many more functions than previously available with the C90-compliant libraries. As the MPLAB XC8 C Compiler targets freestanding applications, not all C99 library features are available and some of these limitations are detailed in the sections following. In addition, these libraries are only available for PIC18 devices, and for Enhanced Mid-range devices that are using the compiled stack model. Other devices can continue to use the C90-compliant libraries.

Librarian Driver

Libraries are now managed using a new librarian driver, xc8-ar. This librarian accepts GNU-archiver-style options and can be used to build and modify all 8-bit compiler libraries.

C99 Language Additions and Limitations

The C99 standard provided many additional features to the language. There are many texts which describe these in detail. The more significant C99 features that are now available are mentioned here.

When selecting the C99 standard, programs building for PIC18 devices can use 64-bit long long integers. The _Bool type is now supported by the compiler for all devices. The printf() function has been expanded to include C99 placeholders for these new types. Hexadecimal floating-point constants, as well as compound literals, can now be specified in the source code. Preprocessor macros can now use a variable number of arguments.

Being a freestanding implementation targeting small-memory devices, not all C99 features are usable. All functions supporting streams, files, signals, and locales are not present in the libraries. Compiler support for complex and imaginary numbers is not present. Wide and multi-byte characters and types are not supported, nor are extended characters permitted in identifiers. Variable length arrays and flexible array members cannot be used in your source code.

Changes

There are a number of areas in which you will experience changes made to the compiler. Some of these changes will require modification to source code that is migrated to using C99.

File Extensions

If you are using the new xc8-cc driver, the extensions used by files accepted and output by the compiler have changed. The following table shows the new extensions used by the new driver. The MPLAB X IDE will produce files with these new extensions when building projects.

File Type Previous Extension New Extension
Preprocessed C source .pre .i
P-code library .lpp .a
Object-code library .lib .a
Object file .obj .o
Assembly source .as or .asm .s (.S, .sx)

Options

If your projects are managed by the MPLAB X IDE, then it will convert your project options over to the nearest equivalent when you select the MPLAB XC8 2.0 compiler in the project properties. If you build on the command line or are using makefiles, you will need to convert the options over manually. Note that options with the xc8-cc driver are case sensitive, which was not the case with xc8.

The following shows the mapping between the more commonly used options.

Feature Previous Option Equivalent Option
Optimization --mode=free --opt=none -O0
Optimization --mode=free -O1
Optimization --mode=std -O2
Optimization --mode=pro* --opt=+speed -O3
Optimization --mode=pro* --opt=+space -Os
Optimization --opt=+asmfile -fasmfile
Device selection --chip -mcpu
Intermediate file output -c or -C -c
Output file --pre -E
Assembly list file --asmlist -Wa,-a
Map file -M<file> -Wl,-Map=<file>
Keyword control --addrqual -maddrqual
Linker Options -L-<option> -Wl,-<option>
Program image offset --codeoffset -mcodeoffset
Memory specification --rom / --ram -mram / -mram
Stack management --stack -mstack

* Subject to your license allowing this optimization level.

Integer Types

If you are using C99, the short long int types that were previously available must now be accessed using the __int24 and __uint24 types (note the double underscore with these new keywords). The bit integer type must now be specified with the __bit keyword. Do not confuse this with the _Bool boolean type.

Floating-point Types

If you are building for C99, support for 24-bit float and double floating-point types is no longer provided, and these types will be forced to be 32-bits wide.

Absolute Addressing

If you are using C99, variables and functions that were placed at a specific address using the @ address construct must use __at(address) to indicate the address at which the object or function should be located.

Interrupt Functions

Interrupt functions when building with C99 must be defined using the __interrupt() specifier and appropriate arguments.

Inline Assembly

With C99, inline assembly can no longer be specified using the #asm/#endasm directives, and must be specified using the statement form. In addition, this form has changed to using the __asm() keyword.

Language Extensions

The compiler’s support of the IAR and MPLAB C18 non-native syntaxes is no longer supported, regardless of which driver or language standard you are using.

Output Formats

The compiler can no longer build for archaic file formats, such as tek (Tektronic), aahex (American Automation symbolic HEX), bin (binary), and cod (Common Object Description).

Peripheral Libraries

The PIC18 peripheral libraries have been not been supported or shipped with the compiler for several versions. Now, the option to indicate the use of these libraries has also been removed. Library routines, such as those that performed EEPROM and flash access, profiling, trace, and setjmp, have been removed from library files. However, the source code for these routines are generated by the compiler driver, and these source files are compiled and linked into your program when you build. Thus, those devices which were able to use these routines with previous compiler versions can continue to do so.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.