Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why there is a underline before wtoi in function _wtoi which ansi version is atoi?

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 :)

like image 504
NorSD NorSD Avatar asked Apr 19 '14 06:04

NorSD NorSD


2 Answers

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.)

like image 82
James McNellis Avatar answered Oct 20 '22 16:10

James McNellis


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.

like image 1
R Sahu Avatar answered Oct 20 '22 14:10

R Sahu