4.10.1.1 Smart IO For AVR Devices
When using MPLAB XC8 C Compiler, multiple IO library
variants, representing increasingly complex subsets of IO functionality, are available and
are linked into your program based on the -msmart-io
option and how you
use the smart IO functions in your project's source code.
When the smart IO feature is disabled (-msmart-io=0
), a full
implementation of the IO functions will be linked into your program. All features of the IO
library functions will be available, and these may consume a significant amount of the
available program and data memory on the target device.
When the smart IO feature is enabled (-msmart-io=1
or
-msmart-io
), the compiler will link in the least complex variant of the
IO library that implements all of the IO functionality required by the program, based on
the conversion specifications detected in the program's IO function format strings. This
can substantially reduce the memory requirements of your program, especially if you can
eliminate in your program the use of floating-point features in calls to smart IO
functions. This is the default setting.
The compiler analyzes the usage of each IO function independently, so while the code for a
particular program might require that the printf
function be full
featured, only a basic implementation of the snprintf
function might be
required, for example.
If the format string in a call to an IO function is not a string literal,
the compiler will not be able to detect the exact usage of the IO function, and a
full-featured variant of the IO library will be linked into the program image, even with
smart IO enabled. In this instance, the
-msmart-io-format="fmt"
option can be used to
specify those conversion specifications that have been used in non-literal format
strings, allowing a more optimal library to be linked. You must ensure that your program only uses the indicated conversion
specifications; otherwise, IO functions may not work as expected.
vscanf("%d:%li", va_list1);
vprintf("%-s%d", va_list2);
vprintf(fmt1, va_list3); // ambiguous usage
vscanf(fmt2, va_list4); // ambiguous usage
When processing the last two calls, the compiler cannot deduce any usage information from
either of the format strings. If it is known that the format strings pointed to by
fmt1
and fmt2
collectively use only the
%d
, %i
and %s
conversion specifiers,
the
-msmart-io-format=fmt="%d%i%s"
option should be issued.
These options should be used consistently across all program modules to ensure an optimal selection of the library routines included in the program image.