ft_printf disc

ft_printf

C project · variadics, libc

printf rebuilt from scratch: chars, strings, pointers, decimals, unsigned and hex.

Open it in the console View the code on GitHub Resume (PDF) LinkedIn

The problem

Rebuild printf from libc from scratch.

What I built

The hard part

Where the va_list lives. The first draft passed it by value to the function that handles each conversion, which works by accident on x86-64 Linux, but on an arm64 Mac each call reads from its own copy: %u %u %u with 1, 2, 3 prints 1 1 1, and %d %s reads the int back as a string pointer and crashes. The handler now takes a pointer, so every conversion moves the same list forward. %p with NULL prints (nil), as glibc does, where macOS prints 0x0.

Built with

More projects