Skip to main content

IAR Embedded Workbench for RL78 5.20

Formatters for scanf

In this section:

In a similar way to the printf function, scanf uses a common formatter, called _Scanf. The full version is quite large, and provides facilities that are not required in many embedded applications. To reduce the memory consumption, two smaller, alternative versions are also provided. Note that the wscanf versions are not affected.

This table summarizes the capabilities of the different formatters:

Formatting capabilities

Small/

SmallNoMb†

Large/

LargeNoMb†

Full/ FullNoMb†

Basic specifiers c, d, i, o, p, s, u, X, x, and %

Yes

Yes

Yes

Multibyte support

Yes/No

Yes/No

Yes/No

Floating-point specifiers a, and A

No

No

Yes

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

No

No

Yes

Conversion specifier n

No

No

Yes

Scan set [ and ]

No

Yes

Yes

Assignment suppressing *

No

Yes

Yes

long long support

No

No

Yes

wchar_t support

No

No

Yes

Table 63. Formatters for scanf 


NoMb means without multibytes.

The compiler can automatically detect which formatting capabilities are needed in a direct call to scanf, 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 scanf formatter.

EWICO.pngTo manually specify the scanf 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.

CLICO.pngTo manually specify the scanf formatter from the command line:
  • Use one of these ILINK command line options:

    ‑‑redirect __Scanf=__ScanfFull
    ‑‑redirect __Scanf=__ScanfFullNoMb
    ‑‑redirect __Scanf=__ScanfLarge
    ‑‑redirect __Scanf=__ScanfLargeNoMb 
    ‑‑redirect __Scanf=__ScanfSmall
    ‑‑redirect __Scanf=__ScanfSmallNoMb 

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 ‑‑scanf_multibytes.