printf
A School 21 project.
# Useful
- Testers
- Misc
- C debugging, compilation and building
- Пилим printf() своими руками. Часть первая. | by Weston Normcore | Medium
Важное отступление: чтобы считать аргумент типа char, нужно передать в va_arg тип int. Особенностей реализации мы здесь касаться не будем, просто запомните, что char считывается через int. More info.
Return value of built-in printf
is the number of characters printed (returned). If an error occurred, the value is negative.
# To-do
- Ensure that functions from
libft
don’t leak intoprintf
. UPD: that’s kinda impossible under Norminette and subject constraints.
# Notes
Variadic functions in C are dangerous. In case of type mismatch or wrong number of arguments the program crashes. See this and this questions on Stack Overflow.
In case of too many (or to few) arguments, passed to the built-in printf, a warning is raised. Though with flags -Wall -Werror -Wextra
it won’t even compile. In case of argument type mismatch, I think the behavior is undefined.
# Things from man 3 printf
The format string is composed of zero or more directives: ordinary characters (not %
), which are copied unchanged to the output stream; and conversion specifications, each of which results in fetching zero or more subsequent arguments. Each conversion specification is introduced by the character %
, and ends with a conversion specifier. In between there may be (in this order) zero or more flags
, an optional minimum field width
, an optional precision
and an optional length
modifier.