Skip to main content Skip to local navigation

Programming 8-bit PICs: which C standard?

Microcontrollers are usually programmed in C, a traditional programming language that dates back to the 1970s. Here I'll talk about a specific type of microcontroller family, the PIC16 (or PIC18) and the compiler options for it.

XC8 supports C89, C90 and C99 (for PIC16/18)

When programming an 8-bit PIC like a PIC16 or PIC18, it's sometimes important to know which version of C that we're using. Unlike newer 32-bit or 64-bit machines that can be compiled with the latest C or even C++ compilers, when you program an embedded device like a PIC16 or PIC18 you're likely having to work with a pre-2000 compiler standard. The question is, which one?

Before about 2023, the XC8 compiler (version "1") aimed to comply with the 1989 standard of C, called C89.

After 2023, the second and third versions of the XC8 compiler for 8-bit PIC microcontrollers introduced support for C90 and C99. You can see this summed up succinctly in the following screen-grab from the MPLAB X compiler:

Compiler properties options window in MPLAB X 6 for XC8 complier, version 3. Shows C90 and C99 options after Version 2 of the compiler, but only C89 before that.

According to the manual for Version 3 of XC8 for PIC, the latest version of the compiler, with support for C99 which "uses an implementation of Clang version 18.1.8 based upon LLVM 18.1.8." (source: Version 3 manual)

Yes, embedded devices are notoriously slow to get up-to-date tools but that's an impressive 26 year gap between today's compiler and the standard it follows. At this rate, we are likely to see support for C23 in 2050 unless open-source projects like LLVM-PIC get off the ground or if Microchip's adoption of LLVM is a sign that they're taking compiler development more seriously. The question is, will 8-bit PICs still be around then? Given that Microchip is one on the only chip manufacturers left standing I think that they very might well be.

Note about AVR compiler with XC8

Complicating this is that when Microchip bought Atmel it also incorporated the AVR series of 8-bit microcontrollers into its portfolio and added the open-source gcc compiler as an option for 8-bit compiling, but only for AVR devices like the Arduino's ATMEGA328. The selection between the PIC and AVR compilers, both under the XC8 hood, is mostly transparent to the developer when working with the MPLAB X IDE.


a pen

James Andrew Smith is a Professional Engineer and Associate Professor in the Electrical Engineering and Computer Science Department of York University’s Lassonde School, with degrees in Electrical and Mechanical Engineering from the University of Alberta and McGill University.  Previously a program director in biomedical engineering, his research background spans robotics, locomotion, human birth, music and engineering education. While on sabbatical in 2018-19 with his wife and kids he lived in Strasbourg, France and he taught at the INSA Strasbourg and Hochschule Karlsruhe and wrote about his personal and professional perspectives.  James is a proponent of using social media to advocate for justice, equity, diversity and inclusion as well as evidence-based applications of research in the public sphere. You can find him on Twitter.  You can find him on BlueSky. Originally from Québec City, he now lives in Toronto, Canada.