Skip to content

Commit 81de027

Browse files
stephanosiocarlescufi
authored andcommitted
doc: languages: c: Add formatted output section
This commit adds "Formatted Output" section to the "C Language Support" documentation that describes the C library-specific formatted output support details. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent 87b39c5 commit 81de027

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

doc/develop/languages/c/index.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ application.
6363

6464
.. _`C Standard Library`: https://en.wikipedia.org/wiki/C_standard_library
6565

66+
.. _c_library_formatted_output:
67+
68+
Formatted Output
69+
****************
70+
71+
C defines standard formatted output functions such as ``printf`` and
72+
``sprintf`` and these functions are implemented by the C standard
73+
libraries.
74+
75+
Each C standard library has its own set of requirements and configurations for
76+
selecting the formatted output modes and capabilities. Refer to each C standard
77+
library documentation for more details.
78+
6679
.. _c_library_dynamic_mem:
6780

6881
Dynamic Memory Management

doc/develop/languages/c/minimal_libc.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ with a number of different toolchains.
1515
The minimal libc implementation can be found in :file:`lib/libc/minimal` in the
1616
main Zephyr tree.
1717

18+
Formatted Output
19+
****************
20+
21+
The minimal libc does not implement its own formatted output processor;
22+
instead, it maps the C standard formatted output functions such as ``printf``
23+
and ``sprintf`` to the :c:func:`cbprintf` function, which is Zephyr's own
24+
C99-compatible formatted output implementation.
25+
26+
For more details, refer to the :ref:`Formatted Output <formatted_output>` OS
27+
service documentation.
28+
1829
Dynamic Memory Management
1930
*************************
2031

doc/develop/languages/c/newlib.rst

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ Nano Newlib
4343

4444
The Newlib nano variant (:file:`libc_nano.a` and :file:`libm_nano.a`) is the
4545
size-optimized version of the Newlib, and supports all features that the full
46-
variant supports except the ``long long`` and ``double`` type format
47-
specifiers.
46+
variant supports except the new format specifiers introduced in C99, such as
47+
the ``char``, ``long long`` type format specifiers (i.e. ``%hhX`` and
48+
``%llX``).
4849

4950
This variant can be enabled by selecting the
5051
:kconfig:option:`CONFIG_NEWLIB_LIBC` and
@@ -61,6 +62,22 @@ the Newlib nano variant is enabled by default unless
6162

6263
.. _`Newlib`: https://sourceware.org/newlib/
6364

65+
Formatted Output
66+
****************
67+
68+
Newlib supports all standard C formatted input and output functions, including
69+
``printf``, ``fprintf``, ``sprintf`` and ``sscanf``.
70+
71+
The Newlib formatted input and output function implementation supports all
72+
format specifiers defined by the C standard with the following exceptions:
73+
74+
* Floating point format specifiers (e.g. ``%f``) require
75+
:kconfig:option:`CONFIG_NEWLIB_LIBC_FLOAT_PRINTF` and
76+
:kconfig:option:`CONFIG_NEWLIB_LIBC_FLOAT_SCANF` to be enabled.
77+
* C99 format specifiers are not supported in the Newlib nano variant (i.e.
78+
``%hhX`` for ``char``, ``%llX`` for ``long long``, ``%jX`` for ``intmax_t``,
79+
``%zX`` for ``size_t``, ``%tX`` for ``ptrdiff_t``).
80+
6481
Dynamic Memory Management
6582
*************************
6683

0 commit comments

Comments
 (0)