ARM Technical Support Knowledge Articles

How do the ARM Compilers handle printf, sprintf, fprintf and scanf?

Applies to: ARM Developer Suite (ADS), RealView Developer Kit (RVDK) for OKI, RealView Developer Kit (RVDK) for ST, RealView Developer Kit for XScale (RVXDK), RealView Development Suite (RVDS)

Answer

In ADS1.2 and RVCT 2.0 and later, the ARM libraries contain standard versions of the scanf and printf family of functions, and also a more efficient variant of each which do not support all format specifiers, e.g., _printf and _scanf. The compiler generates calls to the more efficient variants where possible, e.g., where no floating point arguments are used.

In RVCT 2.1 and later, there are several variants of each function optimized for specific argument types, for example, __0printf (RVCT 2.x/3.0), __1printf (RVCT 3.1), __2printf (RVCT 4.0), _fprintf_* and _scanf_*. These more specific variants are smaller and faster than the general purpose versions. The ARM C compiler will generate calls to these functions instead of the standard function. For example, the RVCT 4.0 compiler will change the call to printf into a call to __2printf but also emit references to symbols like _printf_c and _printf_x depending on the format string/argument types. The linker takes these references into account and ensures that a specialised version that is smaller and faster is used. You could also see calls to variants of printf specific to a version of the ISO C standard, e.g., __c89printf

With RVCT 2.x you can disable the use of the variants if required (for example, if you are reimplementing printf or scanf) using the undocumented compiler switch -Ono_fp_formats. When compiling with this option the compiler will only generate calls to the standard named function.

In RVCT 3.0 and later, you should use the documented option --library_interface=aeabi_clib. This will also disable other optimizations for situations where you will be linking with a C library other than the RVCT library.

In ADS you should write a replacement function _printf, e.g., which simply calls printf (likewise for _scanf).

Article last edited on: 2009-06-26 17:21:29

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential