5.11.2.1 Smart IO For PIC Devices
When using MPLAB XC8 for PIC MCUs, the code that processes the smart IO function format
strings is defined in two source files (doprnt.c for input;
doscan.c for output) and implements all the conversion specifiers,
length modifiers, precision specifiers, field widths, and flags that can appear in these
format strings. These features are implemented by individual sections of code that are
conditionally included into the program image based on how you use the IO functions in your
project. Tracking of the features used by smart output functions is conducted independently
to that for smart input functions, but there is no other differentiation between functions,
as the formatting code is shared between functions. That is, the code that processes the
format strings used by printf
functions for example is the same as that
used by vsnprintf
; only the code that writes to the destination is
different.
If the format string in a call to an IO function is not a string literal, the compiler will not be able to detect which features of the IO function have been used. A more complete version of the formatting routine will be included in the program image; however, the compiler can still make certain assumptions. In particular, the number and type of the arguments following the format string can be used to determine which placeholders could be valid. This enables the size and complexity of the generated formatting routine to be kept to a minimum, even in these cases.
printf(myFormatString, 4, 6);
the compiler
could at least determine from the type of the arguments that no floating-point placeholders
are required for output functions, and so exclude those from the program image.The analysis and customization of the smart IO library code is automatic. There are no options to control this operation. Those IO features linked into the program image can only be controlled by adjusting the format strings used by the smart IO functions in your program. Eliminating the use of floating-point specifiers and modifiers in calls to smart IO function in your program will make the largest reduction to code size.
Although the smart IO functions are regenerated from the original source code with each
build, they are first packaged into a library file before being passed to the linker. This
allows the functions to be replaced in the usual way by user-defined functions with the
same name, if for example you wanted to define your own (non-smart)
printf()
function.