Does the number of values printed by printf depend on the memory allocated for a specific program or it can keep on printing the values?
The printf() function sends a formatted string to the standard output (the display). This string can display formatted variables and special control characters, such as new lines ('\n'), backspaces ('\b') and tabspaces ('\t'); these are listed in Table 2.1.
Printf in Assembly To call printf from assembly language, you just pass the format string in rdi as usual for the first argument, pass any format specifier arguments in the next argument register rsi, then rdx, etc.
The C Standard documents the minimum number of arguments that a compiler should accept for a function call:
C11 5.2.4.1 Translation limits
The implementation shall be able to translate and execute at least one program that contains at least one instance of every one of the following limits:
...
127 arguments in one function call
...
Therefore, you should be able to pass at least 126 values to printf
after the initial format string, assuming the format string is properly constructed and consistent with the actual arguments that follow.
If the format string is a string literal, the standard guarantees that the compiler can handle string literals at least 4095 bytes long, and source lines at least 4095 characters long. You can use string concatenation to split the literal on multiple source lines. If you use a char
array for the format string, no such limitation exists.
The only environmental limit documented for the printf
family of functions is this:
The number of characters that can be produced by any single conversion shall be at least 4095
This makes the behavior of format %10000d
at best defined by the implementation, but the standard does not mandate anything.
A compliant compiler/library combination should therefore accept at least 126 values for printf
, whether your environment allows even more arguments may be defined by the implementation and documented as such, but is not guaranteed by the standard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With