Nios® V Processor Software Developer Handbook

ID 743810
Date 9/26/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

6.11.5.1. Definition of 'asnprintf()'

newlib implements a maze of 22 printf() variants, all based on the same core engine, and all with slightly different interfaces. Some are specified by the C standard, some by Posix, some are GNU extensions, and some are newlib extensions. The newlib libc web page documents the functions that conform to their respective standards.

For more information about libc, refer to the The Red Hat newlib C Libray web page.

The 22 variants fill a four-dimensional space of design alternatives:
  • Plain vs varargs
  • File vs buffer output
  • Output buffer management alternatives:
    • Fixed buffer, unknown length
    • Fixed buffer, known length
    • malloc()ed-and-returned buffer
    • realloc()-able buffer
  • Plain vs no-floating-point formatting support

The map to the maze is the set of prefix chars.

v*printf (mnemonic: v-for-varargs)

The canonical printf() functions take a variable number of arguments including one for each percent-specifier in the format string. This is convenient for you, but inconvenient for wrapper functions taking a variable number of arguments and then doing some sort of value-added before invoking the regular printf() library, because C provides no convenient, portable way for a function to read a variable number of arguments and then pass them to another function taking a variable number of arguments. Consequently, for each plain printf() function, the C library provides a v*printf variant which accepts the extra arguments in varargs vector format.

The "plain" (variable number of arguments) printf functions are:
  • fprintf()
  • printf()
  • asprintf()
  • asnprintf()
  • snprintf()
  • sprintf()
  • fiprintf()
  • iprintf()
  • asiprintf()
  • asniprintf()
  • sniprintf()
  • siprintf()
The fixed-number-of-argument (vararg-based) variants are:
  • vprintf()
  • vasprintf()
  • vasnprintf()
  • vsprintf()
  • vsnprintf()
  • viprintf()
  • vasiprintf()
  • vasniprintf()
  • vsiprintf()
  • vsniprintf()
Note: Despite the mnemonic, these functions are not really integer-only: They also support (for example) unsigned, char and string values.
Lumping all the above variants together, the full list of printf() functions supported by newlib is:
  • fprintf()
  • vprintf()
  • printf()
  • asprintf()
  • asnprintf()
  • snprintf()
  • sprintf()
  • vasprintf()
  • vasnprintf()
  • vsprintf()
  • vsnprintf()
  • fiprintf()
  • iprintf()
  • viprintf()
  • asiprintf()
  • asniprintf()
  • sniprintf()
  • siprintf()
  • vasiprintf()
  • vasniprintf()
  • vsiprintf()
  • vsniprintf()
  • dprintf, vdprintf: Print to a file descriptor (vs FILE*).
  • dprintf, vdprintf: No-floating-point-formatting versions of above.
  • fwprintf, swprintf, vfwprintf, vswprintf, vwprintf, wprintf: Versions with wide-char support.

For more information about these printf() variants, refer to the The Red Hat newlib C Libray web page.