6

Hello! It is confused me for a long time!

Long long ago , there is only ansi version that is atoi .

And now (it is also long long ago ) there is a wide char version .

But why the wide char version has a uderline('_') before wtoi?

Could any one tell me why? Thanks :)

NorSD NorSD
  • 225
  • 4
  • 14
  • Because Microsoft put it there — no other reason. It's their function, so they can do as they like with it; neither `wtoi()` nor `_wtoi()` is standardized except, de facto, by Microsoft. – Jonathan Leffler Apr 19 '14 at 06:43

2 Answers2

6

For the most part, functions that begin with a leading underscore are implementation additions; they are not part of the C Standard Library. (There are exceptions, e.g. _Exit is part of the C Standard Library, though it is not yet implemented in the Visual C++ implementation.) Identifiers that begin with a leading underscore are reserved in the global namespace, so they are used for nonstandard extensions to avoid conflict with user-defined names.

As for why there is no wtoi in the C Standard Library: By the time wide character functions were added to the C Standard Library, it was understood that the atoi interface is flawed because there is no way to detect whether the conversion succeeded or failed.

Do not use atoi or _wtoi. Instead, use the preferable strtol and wcstol functions, both of which are part of the C Standard Library. (There are other similarly-named conversion functions for other types, e.g. strtof and wcstof to convert to float and strtoull and wcstoull to convert to unsigned long long.)

Community
  • 1
  • 1
James McNellis
  • 348,265
  • 75
  • 913
  • 977
1

Microsoft provides the functions _atoi_l, _wtoi, _wtoi_l as vendor specific extensions. They are not standard C/C++ library functions. They have many such vendor specific functions that have names derived from standard C/C++ library functions.

R Sahu
  • 204,454
  • 14
  • 159
  • 270