Atoi is a standard function. But itoa is not. Why


Why this distinction? I've landed up with terrible problems, assuming itoa to be in stdlib.h and finally ending up with linking a custom version of itoa with a different prototype and thus producing some crazy errors.

So, why isn't itoa not a standard function? What's wrong with it? And why is the standard partial towards its twin brother atoi?

Best Solution

No itoa has ever been standardised so to add it to the standard you would need a compelling reason and a good interface to add it.

Most itoa interfaces that I have seen either use a static buffer which has re-entrancy and lifetime issues, allocate a dynamic buffer that the caller needs to free or require the user to supply a buffer which makes the interface no better than sprintf.