NorSD NorSD
NorSD NorSD

Reputation: 233

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

Upvotes: 6

Views: 2412

Answers (2)

James McNellis
James McNellis

Reputation: 354979

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

Upvotes: 6

R Sahu
R Sahu

Reputation: 206567

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.

Upvotes: 1

Related Questions