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

2

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

Phototonus answered 19/4, 2014 at 6:39 Comment(1)
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.Siouxie
F
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.)

Freemanfreemartin answered 19/4, 2014 at 7:59 Comment(0)
U
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.

Unfetter answered 19/4, 2014 at 6:43 Comment(2)
Why the standard C/C++ library does not provide the widechar version ?Phototonus
@NorSDNorSD Good question. I don't know the answer to that.Unfetter

© 2022 - 2024 — McMap. All rights reserved.