Formatters for printf
The printf function uses a formatter called _Printf. The full version is quite large, and provides facilities not required in many embedded applications. To reduce the memory consumption, three smaller, alternative versions are also provided. Note that the wprintf variants are not affected.
This table summarizes the capabilities of the different formatters:
Formatting capabilities | Tiny | Small/ SmallNoMb† | Large/ LargeNoMb† | Full/ FullNoMb† |
|---|---|---|---|---|
Basic specifiers | Yes | Yes | Yes | Yes |
Multibyte support | No | Yes/No | Yes/No | Yes/No |
Floating-point specifiers | No | No | No | Yes |
Floating-point specifiers | No | No | Yes | Yes |
Conversion specifier | No | No | Yes | Yes |
Format flag | No | Yes | Yes | Yes |
Length modifiers | No | Yes | Yes | Yes |
Field width and precision, including | No | Yes | Yes | Yes |
| No | No | Yes | Yes |
| No | No | No | Yes |
† NoMb means without multibytes.
The compiler can automatically detect which formatting capabilities are needed in a direct call to printf, if the formatting string is a string literal. This information is passed to the linker, which combines the information from all modules to select a suitable formatter for the application. However, if the formatting string is a variable, or if the call is indirect through a function pointer, the compiler cannot perform the analysis, forcing the linker to select the Full formatter. In this case, you might want to override the automatically selected printf formatter.
To override the automatically selected printf formatter in the IDE:Choose Project>Options>General Options to open the Options dialog box.
On the Library Options page, select the appropriate formatter.
Use one of these ILINK command line options:
‑‑redirect _Printf=_PrintfFull ‑‑redirect _Printf=_PrintfFullNoMb ‑‑redirect _Printf=_PrintfLarge ‑‑redirect _Printf=_PrintfLargeNoMb ‑‑redirect _Printf=_PrintfSmall ‑‑redirect _Printf=_PrintfSmallNoMb ‑‑redirect _Printf=_PrintfTiny ‑‑redirect _Printf=_PrintfTinyNoMb
If the compiler does not recognize multibyte support, you can enable it:
Caution
Select Project>Options>General Options>Library Options 1>Enable multibyte support.
Danger
Use the linker option ‑‑printf_multibytes.
