If you are developing code for any of Microchip’s 8-bit MCU devices and you wish to upgrade your toolset to include the new version of MPLAB® XC8 C compiler, there are several options available to you. Note in the following suggestions that whenever mentioned, v4.2 or later of the MPLAB X IDE must be run in order to build with the v2.0 MPLAB XC8 compiler and have access to its new features.
Users of PIC® Devices
Given the significant changes that have been introduced in MPLAB XC8 v2.0, users targeting 8-bit PIC devices have several choices when moving forward.
New Driver, C99 Standard, and Libraries
The new xc8-cc driver is recommended for all new projects using the XC8 2.0 compiler. You can swap to using this compiler driver if you have existing MPLAB X IDE projects by simply selecting the v2.0 XC8 compiler toolchain in the Project Properties dialog. Your project will be migrated to the new toolchain, after which some of the compiler controls in the Project Properties dialog will look different to those of previous compiler versions, but these will be assigned a state that will result in a similar build configuration and code execution.
With the XC8 2.0 compiler selected, you can enable the C99 standard in the project’s 'Global' options, as shown in the following figure. New projects will have this language standard selected by default. Use of C99 implies the use of Clang, a new compiler front end, which performs preprocessing and parsing of the C source code. This front end replaces the CPP and P1 applications, however, these applications are still used when building for C90, as described later in this article.
Ensure that you are also using the C99 libraries as shown in the following figure, but note that currently, C99 compliant libraries are only available for projects targeting PIC18 devices and targeting Enhanced Mid-range devices that are using the compiled (non-reentrant) stack model.
For command-line projects, the new driver takes GCC-style options. The options used by existing command-line projects need to be migrated manually unless you choose to use the old driver, as described later in this article. To give you time to convert your projects, most (but not all) xc8 options are accepted by xc8-cc, but triggers warning messages. By default, the new driver builds for the C99 standard, and it uses the C99 libraries (if possible).
New Driver, C99 Standard, C90 Libraries
When using the Clang front end and C99 libraries, some language features are standardised. If you would like to utilize the C99 standard but you are using some of the superseded features, there is an intermediate position you can take when it comes to running the compiler. Select the C99 standard, but specify the C90 libraries. These libraries allow you to continue to use 24-bit floating-point types, for example, which are not normally permitted with C99. Use the -mc90lib option on the command line or the Link in C library control in the project properties, as shown in this figure.
New Driver, C90 Standard, and Libraries
The new xc8-cc driver uses the Clang front end and C99 features by default, however, for new projects and if required, you can revert back to the C90 standard (and hence use the old CPP/P1 compiler front-end) if this language specification is better suited to your application. Use the -std=c90 option on the command line, or the C standard control in the project properties, as shown here.
Old Driver, C99 Standard and Libraries
Although it is recommended that you run the new xc8-cc driver that comes with the XC8 2.0 compiler, the previous driver, xc8, is still shipped in the package and can be run in the same way and using the same command-line options with which you are familiar. The MPLAB X IDE will always use the new driver if you have selected the v2.0 XC8 compiler, however, if you do not use the MPLAB X IDE and have makefiles or build scripts, you can have them continue to use the old driver and options but use some of the new compiler features.
The xc8 driver shipped with XC8 2.0 has a new option: --std=c99 (note the double dash when using the xc8 driver). This allows you to select the C99 language standard and build your project using the Clang front-end. Being able to select C99 without having to change your project build scripts could help you evaluate the effort involved in updating projects.
Old Driver, C99 Standard, C90 Libraries
The xc8 driver shipped with XC8 v2.0 has another new option: --runtime=+c90lib. This allows you to request the use of the C90 libraries while having code generated to the C99 standard and parsed by the Clang front end. This also allows you to continue to use 24-bit floating-point types with C99 code generation.
Old Driver, C90 Standard, and Libraries
If necessary, you can continue to use the old xc8 driver with the same options and C90 standard (and CPP/P1 front-end) as you have in the past. This is the default build configuration if you do not specify a language standard option. Running the compiler in this way does not take advantage of any new features but requires minimal changes to your projects, and it ensures that the compiler output is consistent with the previous versions.