Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between _itoa and itoa?

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?

like image 741
Polaris878 Avatar asked Oct 19 '09 02:10

Polaris878


2 Answers

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.

like image 177
Michael Burr Avatar answered Sep 28 '22 12:09

Michael Burr


The MSDN documentation for itoa() says:

This POSIX function is deprecated beginning in Visual C++ 2005. Use the ISO C++ conformant _itoa or security-enhanced _itoa_s instead.

like image 24
Greg Hewgill Avatar answered Sep 28 '22 10:09

Greg Hewgill