What is the difference between _itoa and itoa?

Polaris878 picture Polaris878 · Oct 19, 2009 · Viewed 18.6k times · Source

Visual Studio is yelling at me about using itoa() saying to use _itoa() instead?

It looks to me like they are the same function. What gives?

Answer

Michael Burr picture Michael Burr · Oct 19, 2009

A C run time library implementation is not supposed to introduce names that aren't in the standard unless they follow a certain naming convention (like starting with an underscore). The earlier versions of Microsoft's compiler didn't follow this rule particularly closely, but over time, Microsoft has been moving more toward making their implementation more standards compliant. So functions they used to supply that would intrude on the user's namespace they have been implementing using names that are reserved for compiler implementations and have been deprecating the old names.

If _CRT_NONSTDC_NO_WARNINGS is defined, the MS compiler won't complain about the itoa() function being deprecated. But it will still complain about it being unsafe (you have to define _CRT_SECURE_NO_WARNINGS to quiet that warning). Or use the safer version of the function (_itoa_s()) that provides the function with the destination buffer size

Both _itoa() and itoa() resolve to the exact same function in the library down to the same address - there is no difference except in the name.