Thursday, October 25, 2018

stop using %i!

Hey me-from-the-past. Here is you-from-the-future. Stop using %i. I know you're used to it because your re-implementation of printf for your own x86 microkernel had only %i for printing numbers instead of the standard %d. I know as well that even in my world, printing %d and printing %i produces the same result, but listen, here's the catch:

scanning for %i enables automated base conversion while scanning for %d guarantees digits are interpreted as decimal numbers and nothing else. You don't want "${width}x${height}" to fail being recognized by "%ix%i" just because it looks so much like a single hex number as soon as width is null, right ?

right.

So stay safe, and stop using it.

No comments: