XC8 Mplab
XC8 Mplab
XC8 Mplab
SEE THE
MPLAB XC8 C COMPILER RELEASE NOTES FOR AVR DOCUMENT
IF YOU ARE USING THE COMPILER FOR 8-BIT AVR DEVICES
Overview
Documentation Updates
What’s New
Migration Issues
Fixed Issues
Known Issues
Microchip Errata
1. Overview
1.1. Introduction
This release of the Microchip MPLAB® XC8 C compiler is a minor update to the v2.05 compiler. This
release includes several new features and bug-fixes.
2.1. Functions
An empty implementation of the getch() function has been provided that can be customised for use in the
scanf family of functions. Customize this function as required, then include the source file into your project.
This function returns an int when used in C99 projects, but a char when used in C90 projects.
3. What's New
The following are new PIC-target features the compiler now supports. The version number in the
subheadings indicates the first compiler version to support the features that follow.
Object .obj .o
New librarian driver A new librarian driver is positioned above the previous PIC libr librarian. This driver
accepts GCC-archiver-style options, which are either translated for or passed through to the librarian
being executed. The new driver allows a similar set of options with similar semantics to be used to
create or manipulate any PIC library file and is thus the recommended way to invoke the librarian. If
required for legacy projects, the previous librarian can be called directly using the old-style options it
accepted in earlier compiler versions.
Clang front end The compiler's front end, responsible for preprocessing and parsing the C source code, is
now implemented using Clang. This frontend is used when compiling for the C99 standard, regardless
of whether you are using the new (xc8-cc) or previous (xc8) drivers. When using Clang, there might
be differences in how source code is preprocessed, and different warning or error messages might be
produced during the parsing stage.
C99 support By default, the xc8-cc driver will compile for C99 conformance. You can use the -std
option with this driver to explicitly specify the standard, choosing either c90 or c99. The previous xc8
driver builds for the C90 standard by default, although you can request the C99 language standard using
the --std option (note the double dash), in which case the compiler will swap to using Clang as the
front end. New types available with the C99 standard include a 64-bit long long integer types
(currently implemented only for PIC18 devices) and boolean type, but not all other C99 features are yet
implemented. Note also that 24-bit floating-point types are not permitted when building for C99.
If you would like to move towards the C99 standard for existing projects but want to minimise any
changes to your source code, use the xc8-cc driver, set the language standard using -std=c99, and
use the -mc90lib option (if you prefer to use the previous xc8 driver, use the equivalents: --std=c99
and --runtime=+c90lib). This will select the Clang front end, but use C90-compliant libraries and
keep many of the code features (such as 24-bit floating-point types) as they were for the previous
compiler. It is recommended that you use the new xc8-cc driver for new projects.
C99 library support This initial release has limited C99-compliant libraries; furthermore, these libraries are
only available for PIC18 devices and also for Enhanced Mid-range devices that are using the compiled
(non-reentrant) stack model. More complete versions of these libraries will be made available in a
future release. Note also that some routines in the C99 library will be much larger than their C90
counterparts, and that you might see an increase in data memory, program memory, or stack usage.
These routines will be optimized in future releases.
See the user's guide for the available functions, but note that the following functions are only available
for PIC18 devices:
lldiv_t exp2
atoll exp2f
strtoll exp2l
strtoull fma
llabs fmaf
lldiv fmal
time_t llrint
difftime llrintf
mktime llrintl
time llround
ctime llroundf
gmtime llroundl
localtime
Better interrupt response in Free mode The list of registers saved when using the lower optimization levels
now more closely matches that with level s/3 (formerly PRO mode).
New device support Support is available for the following PIC parts (and their corresponding LF variants):
16F18455 and 16F18456.
4. Migration Issues
The following are features that are now handled differently by the compiler. These changes may require
modification to your source code if porting code to this compiler version. The version number in the
subheadings indicates the first compiler version to support the changes that follow.
5. Fixed Issues
The following are corrections that have been made to the compiler. These might fix bugs in the generated
code or alter the operation of the compiler to that which was intended or specified by the user's guide. The
version number in the subheadings indicates the first compiler version to contain fixes for the issues that
follow. The bracketed label(s) in the title are that issue's identification in the tracking database. These may be
useful if you need to contact support.
6. Known Issues
The following are limitations in the compiler's operation. These may be general coding restrictions, or
deviations from information contained in the user's manual. The bracketed label(s) in the title are that issue's
identification in the tracking database. This may be of benefit if you need to contact support. Those items
which do not have labels are limitations that describe modi operandi and which are likely to remain in effect
permanently.
6.1. MPLAB X IDE Integration
MPLAB X IDE update If you encounter the MPLAB X IDE error The program file could not be
loaded for projects that use the compiler’s (default) ELF output, please update your IDE to at least
version 2.30. There was an issue in the ELF loader that triggered this error and prevented projects from
being debugged, but which has been resolved. If you cannot update the IDE, switch your project
settings to COFF output.
MPLAB IDE integration If Compiler is to be used from MPLAB IDE, then you must install MPLAB IDE
prior to installing Compiler.
MPLAB X IDE library builds See the New Features section for information pertaining to debugging library
files.
Wrong referenced values shown (XC8-1758) Where a structure contains a member that is a pointer to
another structure and that other structure contains a function pointer member, the IDE watch view
might incorrectly show the values contained in the other structure.
Wrong parameter location shown (XC8-1565) In some cases, where the definitions of a function's
parameters were spread over multiple lines and the argument of the first parameter was originally stored
in WREG, the debug information relating to the location of the parameter might have been incorrect
and the IDE indicated an address WREG0 (CPU), even if the parameter was moved to memory. As a
workaround, consider placing the name of the function and its first parameter on the same source line,
or use the option -Xxc8 -W--dwarf-use-loclists=never.
Debugging problems when using of macro for header name (XC8-1438) When including a header file
whose name is specifier as a preprocessor macro, can result in incorrect line number information in the
debugging files which would affect the ability to set breakpoints and step code. This issue only affects
projects using the P1 parser.
Can't find space with absolutes (XC8-1327) In projects that used absolute addressed objects in program
memory, a "cannot find space" error might have occurred, as a result of the assembler's psect-merging
optimization. In such case, the issue can be worked-around by either disabling psect-merging (i.e. using
the option -Wa,-no_merge) or by reserving the program memory occupied by those objects (using -
mrom or -mreserve).
CMF error for maverick code (XC8-1279) Code or data that is not explicitly placed into a psect will
become part of the default (unnamed) psect. Projects containing assembly code that were placed in such
a psect caused the compiler to emit the error "(1437) CMF error: no psect defined for the line". As a
workaround, place the assembly code in an appropriate psect. Using the default psect at any time is not
recommended.
Use of XC8 in MPLAB IDE v8 is now deprecated (XC8-1228) As of MPLAB XC8 v1.34, the use of
MPLAB 8 IDE is deprecated, and the installation of the DLL files that the IDE used to interface to XC8
are removed from the compiler installer.
ELF debugging issues Not all aspects of the ELF/DWARF debugging file have been implemented. MPLAB
XC8 version 1.30 implements DWARF version 3 which allows for improved debugging. Only MPLAB
X IDE supports ELF, but you must ensure that you are using a version of this IDE that can process ELF
files produced by the compiler. The following are some of the issues that may not work as expected
with this release of the compiler.
• Unused variables (XC8-747) will not be identified in the ELF file.
• Constant propagation optimizations (XC8-744) may affect which variables are watchable in the IDE
or the values that are indicated in the Watch window.
• In-line C functions (XC8-748) will not be debuggable.
• Procedural abstraction (XC8-749) will affect the operation of breakpoints.
• External memory variables (MPLABX-2004, MPLABX-2255, and others) will not be displayed
correctly in the Watch window.
• The type name (as opposed to the object's name) that appears for an anonymous structure or union
typedef or an enumerated typedef will be shown as "." in the Watch window.
• The type name displayed for an identifier that was declared using a typedef type will be the identifier's
semantic type rather than its typedef type in the Watch window.
6.2. Code Generation
Constant propagation (XC8-1903) The constant propagation optimizations might not correctly pick up that
calls to duplicated functions (since they are called from more than one call graph) might alter the initial
value in variables, and code following the call might have access to variables replaced with incorrect
constant values.
Bogus warning regarding structure sizes (XC8-1900) When building for C99, the parser is incorrectly
assuming that structure members are word aligned and there are occasionally warning messages
produced that imply a structure has an incorrect size. This issue does not, however, affect the generated
code, which will function as expected.
Initialization of linear objects (XC8-1887) When building enhanced mid-range projects that define more
than one large initialized object, these objects are being placed in linear memory in an order which does
not match the order of their initial values. As a work around, initialize them inside the main() or other
functions.
Inappropriate and missing types (XC8-1886) The <stdint.h> header used by C99 builds defines
(u)int_fast16_t as being types with a size of 4 bytes, whereas a type with a width of 2 bytes would
be the fastest types. The (u)int_fast24_t types are missing entirely.
Unsupported directive (XC8-1817) The DDW assembly directive is not supported.
Bogus warning for absolute functions (XC8-1809) Functions that are made absolute might trigger the
warning (1262) object "*" lies outside available data space when compiling for
devices that have vectored interrupts, e.g. a PIC18F25K42. This warning can be ignored.
Replacing IO functions (XC8-1806) The compiler does not support user-defined implementations of any of
the compiler-generated printf()/scanf() family of functions. If you must define these, use a unique
function name, but note that as the supplied functions are tailored to your project, they are already very
efficient.
Generate no code warning (XC8-1803) Some of the C99 standard library character classification functions
(viz. isalpha(), isdigit(), isgraph(), islower(), isprint(), isspace(), and isupper())
will cause the compiler to emit the warning expression generates no code. This is a side-effect
of their implementation, and can be safely ignored.
FLT_ROUNDS macro not defined (XC8-1791) The FLT_ROUNDS macro, which should be defined by
<float.h> is not defined and its use will result in an undefined symbol error.
Excessive consumption of decimals (XC8-1790) The A, E, F, and G conversion specifiers in the C99
scanf() functions will consume 'p' and 'P' in decimal numbers.
Special float strings not recognised (XC8-1789) The A, E, F, and G conversion specifiers in the C99
scanf() functions do not recognise strings representing infinity and NaN (not a number).
Errno affects scans (XC8-1786) If the errno variable is non-zero before calling any of the C99 scanf()
functions, then any of the following conversion specifiers will fail: A, D, E, F, G, O, S and X.
Character set conversions not supported (XC8-1785) The %[] character-set conversion specifiers in the
C99 scanf() functions are not supported.
White space not counted (XC8-1784) The %n conversion-specifier in the C99 scanf() fails to count white-
space in the input string.
Error not set for string conversions (XC8-1782) The C99 strtod() family of functions (including
strtof() and strtold()) do not set errno to ERANGE for values outside the representable range.
Scanning hex floating-point (XC8-1781) The C99 scanf() a, e, f, and g conversion specifiers will only
convert the leading zero of any hexadecimal floating-point constant. This results in an assignment of
zero to the function arguments which receive the converted input, and the remainder of the string from
the x character is scanned according to the format string.
Undetected bad config values (XC8-1771) If the argument to the #pragma config directive is a literal
numerical value with a valid initial value followed by illegal characters, for example #pragma
config CONFIG2L=0todo, the initial portion of the value is read and the remainder silently ignored.
This might be encountered of you accidentally attempt to specify a binary value to this pragma, using a
0b prefix.
fmod() and zero (XC8-1641) The fmod() library function is non-compliant when second argument is zero.
Currently, it returns the first argument in this case. It should return either trigger a domain error or
return zero.
Can't generate code for floating-point operations (XC8-1613, XC8-1614) Expression that perform
operations on the results of two complex floating-point expression, e.g. use of the || operator in the
following(( ! *pd2) - d2) || (((f1)-- ) >= *pf3)), might trigger can't generate code error
messages.
String literal expressions (XC8-1610) Accessing a character of a string literal might produce an error
message when using the initialize an object, e.g. volatile int a = "abc"[1];.
Too many side-effects (XC8-1587) Incorrect PIC18 code is being generated for expressions involving
compound assignment operators and where the lefthand side has side-effects. In this cases, the side-
effects of the lefthand side will occur twice.
IDLOC value truncation (XC8-1570) The IDLOC values for some devices, e.g. PIC18F8723, are currently
limited to being 4-bits wide. The truncation can be removed by editing the .cfgdata file (located in
the dat directory) corresponding to your device, and changing the mask value, bolded in this example:
CWORD:200000:F:FF:IDLOC0
to the required value, for example:
CWORD:200000:FF:FF:IDLOC0
Register over-writes with recursive functions (XC8-1563) In some binary expressions or sub-expressions
located in a recursively-called function, the compiler may allocate a static register to one sub-tree that
might be clobbered by a recursive function call made in the other sub-tree. In this case, the compiler
will now emit a warning message to indicate that the register might be corrupted.
Bad intermediate code from typedefs (XC8-1560) In some cases where a member of a structure has a
typedefed type that is used in a previous definition before the structure, the code generator will emit the
error message "bad intermediate code". This can possibly be worked-around by ensuring that the
structure is the first definition to use the typedef'd type.
Non-removal of unused variables (XC8-1480) If a global variable is defined outside of library code and has
had its address taken by a non-library function that is not called, the variable has memory allocated,
even if it has not otherwise been used.
Device oscillator calibration (XC8-1280) Oscillator calibration using --RUNTIME=+config will not work
with new devices that obtain their calibration constant from a calibration word stored in flash program
memory, such as the MCP19114/5 devices. Disable this runtime sub-option and refer to the device data
sheet for instructions.
Bogus warning of arithmetic overflow when subtracting (XC8-1270, XC8-1585) A warning regarding an
arithmetic overflow in constant expression might be issued by the compiler when the
expression contains a literal subtraction. This warning can usually be ignored. A recent change in the
default wanting level imposed by the MPLAB X IDE has seen this compiler warning issued more
frenetically by the compiler.
Inline assembly not output in PRO mode (XC8-1268) In PRO mode, inline assembly code enclosed in
#asm - #endasm is simply not output by the code generator. The presence of any instruction in an
asm(""); statement before the #asm assembly results in the correct behaviour. Alternatively, you can
place the #asm block inside braces { }.
Printing spaces to width (XC8-1214) When using a %d placeholder and a width specifier, the C90
implementation of printf() function did not print leading spaces in the output when the printed value
had few characters that the specified width, so for example the format string "%04.2d" might print
"77" instead of " 77". The C99 printf() function is not affected by this issue.
Functions called from in-line assembly(XC8-1180) The code generator will not be able to identify a C
function called only from in-line assembly code if the definition for that C function is placed before the
assembly call instruction in the source file. Placing the function definition after the call is acceptable. If
the function cannot be identified, no code will be generated for the function and the linker will issue
undefined symbol errors.
Printf modifiers 'h' and 'L' ignored (XC8-1166) A printf() conversion specification that uses the h or L
modifiers will result in the specification itself being printed, e.g. %hx will print hx. This does not affect
the printf() in the C99 libraries.
Rogue cast warning (XC8-1122, XC8-1429) When assigning a value to a variable with a smaller type, a cast
to the destination type does not suppress the arithmetic overflow in constant expression
warning issued by the compiler.
Messy cleanup (XC8-1087) Running an XC8 ports-support uninstaller might leave behind several directories
in the compiler’s main directory.
Redefinition of intrinsic functions (XC8-1061) It not possible to replace a standard library function which
uses the intrinsic pragma with a user-defined function with the same name. Examples of standard
library functions that might use this pragma are: all of the inline delay functions (such as _delay()),
memcpy(), and __va_start().
Can’t generate code error (XC8-1055) Interrupt code which indirectly calls a function and uses the return
value of this call as a parameter to another function has been seen to trigger can’t generate code errors.
Split the statement so the call is made and the result assigned to a temporary variable. Pass the
temporary variable to the subsequent call.
Accessing flash data memory (XC8-1047) None of the supplied flash library routines or macros associated
with flash support those devices that utilize flash data memory. Devices without flash data memory are
not affected by this limitation.
Persistent memory check functions (XC8-1029) The persist_check() and persist_validate()
functions that were provided previously do not work with the new memory allocations schemes used by
the compiler. These functions have been removed from the libraries and are not available for use.
Can’t generate code errors (XC8-1022) In Free and PRO modes, code which indirectly accesses nested
structure members might produce can’t generate code errors.
Indirect function calls (XC8-1000) For midrange and baseline devices, there is a limit on the number of
functions that can be called indirectly via a pointer. Typically this will be about 120 functions, but this
limit is dependent on where the functions are linked. Code might crash if this limit is exceeded. This
does not affect enhanced mid-range devices.
Multiple-assignment expressions (XC8-995) The compiler can crash when compiling a statement that
involves multiple assignments and the assignment operands have side effects (such as referencing
volatile objects), e.g. a = b = c = d = e =... Break up offending statements into many small
ones.
Fedora path variable (XC8-474) The path variable will not be updated when non-root users install the
compiler under Fedora. If you wish for the compiler driver to be in your path, update your path variable
manually after installation of the compiler.
No static local specifiers (XC8E-313) The __near and __far object specifiers cannot be used with
static local objects.
Absolute variables in access bank memory (XC8E-138) PIC18 projects that locate absolute variables in the
lower addresses of the access bank RAM might trigger a can’t find space error for the psect
temp in class COMRAM. If a project must define absolute objects, try locating them at a higher address.
Absolute initialized variables (XC8E-63) Variables which are absolute and which are not const cannot be
initialized. The following example will not generate an error, but will not work as expected. Define the
variable as absolute and initialize it in main-line code.
unsigned int varname @ 0x0200=0x40; // will not work as expected
Bank qualifiers (XC8E-62) Only bankx qualifiers for data banks 0 through 3 are supported by the compiler.
(These are enabled using the --ADDRQUAL option). Use absolute variables to place objects in other
banks, if required.
In-line assembly and labels (XC8E-61) Functions which are called from both main-line and interrupt code
should not contain in-line assembly that defines assembly labels. Such labels will not be assigned the
usual duplication prefix (i1, i2 etc) and will result in multiply-defined symbol errors.
Switch strategies (XC8E-20) There is only one possible switch strategy currently available for PIC18
devices. It uses the space switch type. New strategies will be introduced in future compiler versions so
that PIC18 devices have similar options to the baseline/mid-range devices.
Stack overflow (XC8E-11) When the managed stack is used (the stackcall suboption to the --RUNTIME
option is enabled) in some situations the stack may overflow leading to code failure. With this option
enabled, if a function call would normally overflow the stack, the compiler will automatically swap to
using a lookup table method of calling the function to avoid the overflow. However, if these functions
are indirect function calls (made via a pointer) the compiler will actually encode them using a regular
call instruction and when these calls return, the stack will overflow. The managed stack works as
expected for all direct function calls, and for all indirect calls that do not exceed the stack depth.
Non-reentrant library functions Some library functions, for example the printf() family of functions,
are not reentrant and may fail if multiple instances of them are active at the same time. This limitation
exists even if you specify a reentrant stack setting.
New scanf() implementation The compiler does not currently customise the new C99 scanf() function in
the same way as it does with the printf() function. The provided implementation of scanf() is
feature complete, and, as a result, is extremely large. When used, this function's footprint could exceed
the program memory size on your device. It is recommended only for large PIC18 devices when space
is not a critical issue.
Redirecting bss variables If the #pragma psect directive is used to redirect objects that normally reside in
any of the bss psects, the runtime startup code will not be aware of this and will clear the memory that
the variables would have ordinarily be allocated. At such an early stage, this should not affect program
execution, but if all bss objects are redirected, an undefined symbol error will occur with PIC18
devices. Consider using the __section() specifier.
Unsupported functions The strdup() function is not supported. The strftime() function is not
supported for baseline devices.
Installer execution On both Mac OS X and Linux, it is necessary to run the installer as root or with
superuser privileges (using sudo, for example). If the installer is started without superuser privileges on
Mac OS X, it will exit and display an informative message. In the same situation on Linux, the installer
will fail when it attempts to write to directories for which it does not have adequate rights. The
messages displayed will relate to these access failures. For correct operation, run the installer via sudo,
or as the root user, on these systems.
PATH environment variable On Linux systems, the installer, by default, updates the PATH environment
variable to include paths to the new executables being installed. If the installer is run via sudo, the
default action will update the PATH variable of the user executing the sudo command. If the installer is
run by root, the installer will only update root's PATH variable, and not the PATH variables of ordinary
users. If installing the compiler while logged in as root, a better choice is to update all user PATH
variables. Alternatively, skip the step to update the PATH variable in the installer, and manually update
the PATH variables of users who will use the software.
PIC12F529T39A/T48A memory restrictions The previous limitation which restricted memory to the first 4
RAM banks for user-defined variables has been lifted. Note, however, that the compiler will not allow
you to define objects that span multiple banks on these devices.
Psect pragma and data psects As described in the manual, the #pragma psect directive should not be
used to move initialized variables that would normally be located in one of the 'data' psects. The initial
values in program memory and space for the variables themselves in RAM must be built up in a strict
order. Using this pragma will violate this assumption. Consider using the __section() specifier.
Copying compiler header files The header files shipped with the compiler are specific to that compiler
version. Future compiler versions may ship with modified header files. If you copy compiler header
files into your project, particularly if you modify these files, be aware that they may not be compatible
with future versions of the compiler.
Can’t Generate Code messages When compiling for baseline devices, some complex expressions may
cause compile-time errors (712) Can’t Generate Code for this expression. The expressions should be
simplified to work around this. This may require the use of additional variables to store intermediate
results. This is most likely with long integer or floating-point arithmetic and particularly those devices
with less than 4 bytes of common memory available.
Option and tris register access For baseline devices, the OPTION and TRIS registers must be written as a
byte. Writing individual bits is not supported.
PIC17 support PIC 17 devices (for example, 17C756) are not supported by this compiler.
Configuration words (PIC18 parts only) The new device support introduced in PICC18 v9.80 will not
automatically program the default values into the configuration words when no value is specified. If
your project does not program all configuration words explicitly, select the option "Program the device
with default config words" in the Linker tab.
Specifying configuration words on PIC10/12/16 devices The __PROG_CONFIG() and __CONFIG()
macros can be used to specify the configuration words on PIC10/12/16 devices as well as PIC18
devices, but only when building for C90. The __PROG_CONFIG() macro must use a literal constant
argument; you cannot use the configuration setting symbols with this macro. The __CONFIG() macro
must only use the predefined configuration setting symbols and you may not not use a literal value with
this macro.
rfPIC12 parts To use the rfPIC12 parts, for example the rfPIC12C509AF, you will need to specify to the
compiler a part name in a format similar to RF509AF, for example. You can also use an alias like
12C509AF, for example. The full part name is also not appropriate when compiling from MPLAB IDE.
7. Device Errata
For 8-bit PIC devices, this release of the XC8 compiler recognizes the published silicon errata issues listed in
the table below. Some of these issues have been corrected and no longer apply in recent silicon revisions.
Refer to Microchip's device errata documents for details on which issues are still pertinent for your silicon
revision. The compiler's chip configuration file records which issues are applicable to each device. Specific
errata workarounds can be selectively enabled or disabled via the driver's --ERRATA command line option.
All these errata are PIC18 specific, except for the CLOCKSW and BRANCH errata, which applies to
enhanced mid-range devices.
LFSR Using the LFSR instruction to The compiler will load FSR
load a value into a specified registers without using the
FSR register may also corrupt LFSR instruction.
a RAM location.
NVMREG The program will access data The runtime startup code
flash rather than program adjusts the NVMCON register
flash memory after a reset, to ensure that program
affecting runtime startup memory is accessed by table
code. read instructions.