December 28, 2020
The variable arguments in
printf formatting means that it is easy to get type mismatches. The
practical results vary considerably:
printf(â0x%08lxâ, p); // Printing a pointer as an int â truncation or worse on 64-bit
printf(â%d, %fâ, f, i); // Swapping float and int â could print nonsense, or might actually work (!)
printf(â%s %dâ, i, s); // Swapping the order of string and int â will probably crash
[.] (aside: understanding why #2 often
prints the desired result is a good ABI puzzle)
I had to think about this for a bit, and then I realized why and
how it can work (and why similar integer versus float argument