Search code examples
cvisual-studiodeprecatedmsvcrtstandards-compliance

What is the purpose of Microsoft's underscore C functions?


This question is about the same subject as strdup or _strdup? but it is not the same. That question asks how to work around MS's renamings, this question asks why they did it in the first place.

For some reason Microsoft has deprecated a whole slew of POSIX C functions and replaced them with _-prefixed variants. One example among many is isatty:

https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-isatty

This POSIX function is deprecated. Use the ISO C++ conformant _isatty instead.

What exactly is ISO C++ conformant about _isatty? It appears to me that the MSDN help is totally wrong.

The other questions answer explained how to deal with this problem. You add the _CRT_NONSTDC_NO_DEPRECATE define. Fine. But I want to know what Microsoft's thinking is. What was their point in renaming and deprecating functions? Was it just to make C programmers lives even harder?


Solution

  • The fact that _isatty() is ISO C++ conformant makes sense if you think of it like a .

    Under ISO C++, the compiler is only supposed to provide the functions in the standard (at least for the standard headers) -- they're not allowed to freely add extra functions, because it could conflict with functions declared in the code being compiled. Since isatty() is not listed in the standard, providing an isatty() function in a standard header would not be ISO C++ compliant.

    However, the standard does allow the compiler to provide any function it wants as long as the function starts with a single underscore. So -- language lawyer time -- _isatty() is compliant with ISO C++.

    I believe that's the logic that leads to the error message being phrased the way it is.

    (Now, in this specific case, isatty() was provided in io.h, which is not actually a C++ standard header, so technically Microsoft could provide it and still claim to be standards-conformant. But, they had other non-compliant functions like strcmpi() in string.h, which is a standard header. So, for consistency, they deprecated all of the POSIX functions the same way and they all report the same error message.)