19.1 Smart IO Routines

The library code associated with the print and scan families of IO functions can be customized by the compiler with each compilation, based on compiler options and how you use these functions in your project. This can reduce the amount of redundant library code being linked into the program image, hence can reduce the program memory and data memory used by a program.

The smart output (print family) functions are:
printf fprintf snprintf sprintf
vfprintf vprintf vsnprintf vsprintf
The smart input (scan family) functions are:
scanf fscanf sscanf
vfscanf vscanf vsscanf

When this feature is enabled, the compiler analyzes your project's C source code every time you build, searching for calls to any of the smart IO functions. The conversion specifications present in the format strings are collated across all calls, and their presence triggers inclusion of library routines with the associated functionality in the program image output.

For example, if a program contained only the following call:
printf("input is: %d\n", input);
when smart IO is enabled, the compiler will note that only the %d placeholder has been used by the printf function in the program, and the linked library routine defining printf will thus contain a basic functionality that can at least handle the printing of decimal integers. If the following call was added to the program:
printf("input is: %f\n", ratio);
the compiler will then see that both the %d and %f placeholders were used by printf. The linked library routine would then have additional functionality to ensure that all the requirements of the program can be met.

Specific details of how the smart IO feature operates for this compiler are detailed in the following section. The syntax and usage of all IO functions, which are part of the <stdio.h> header, are described in the Microchip Unified Standard Library Reference Guide.