Skip to main content

IAR Embedded Workbench for RISC-V 3.40

Formatters for printf

In this section:

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 c, d, i, o, p, s, u, X, x, and %

Yes

Yes

Yes

Yes

Multibyte support

No

Yes/No

Yes/No

Yes/No

Floating-point specifiers a, and A

No

No

No

Yes

Floating-point specifiers e, E, f, F, g, and G

No

No

Yes

Yes

Conversion specifier n

No

No

Yes

Yes

Format flag +, -, #, 0, and space

No

Yes

Yes

Yes

Length modifiers h, l, L, s, t, and Z

No

Yes

Yes

Yes

Field width and precision, including *

No

Yes

Yes

Yes

long long support

No

No

Yes

Yes

wchar_t support

No

No

No

Yes

Table 58. Formatters for printf 


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.

f0db_IDE_icon.png To override the automatically selected printf formatter in the IDE:
  1. Choose Project>Options>General Options to open the Options dialog box.

  2. On the Library Options page, select the appropriate formatter.

f120_CLI_icon.png To override the automatically selected printf formatter from the command line:
  • 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.