Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Win32 mkdir vs _mkdir

Tags:

c++

posix

winapi

On this page, Microsoft states that POSIX mkdir is deprecated in favour of the "ISO C++ Conformant" _mkdir. The same seems to apply to other similar POSIX functions.

Do they mean deprecated in so far as they are concerned, or is there some standards body (POSIX, ISO?) that has deprecated it?

In what regard is it more ISO C++ compliant, and against which ISO standard is it more compliant?

Unfortunately I do not have access to the actual ISO C++ standards, although I did look at the last freely available draft for C++11 (N3337) and it didn't mention these functions that I could see.

My reason for asking is that I often call these POSIX functions, however I would prefer not to write code against deprecated standards.

like image 497
harmic Avatar asked Oct 25 '15 06:10

harmic


1 Answers

Only the old name is deprecated, not the function, and only in Visual Studio, not in POSIX.

Basically, the reason is that mkdir isn't defined as a runtime library function in the ISO C++ standard, and non-standard runtime library functions are expected to begin with an underscore. Accordingly, Microsoft has added the underscore to all the non-standard function names in the runtime library. Most of these are POSIX-like functions, though there are a few Windows-specific ones.

The section of the standard that defines identifiers that are reserved for use by the implementation is 2.10, paragraph 3. So far as I am aware, the standard does not explicitly state that the implementation cannot use other identifiers, but presumably it is implicit in the fact that such an implementation would be unable to build a legal C++ program which happens to use the same name in an incompatible way.

In this particular case, that is only true if the program includes the relevant implementation-defined headers, so I am not convinced that ISO C++ did in fact require Visual Studio to deprecate the old names, but it appears that Microsoft either believed that it did, or that the use of reserved identifiers is best practice. (Or that being able to compile POSIX source as-is should be discouraged; take your pick!)

Additional note: I would presume that it is also possible for a naming conflict to cause problems during linking for more complicated programs, even when the implementation-defined headers are not included. However, it is not clear that deprecating the functions actually helps in this case, since the old names are still present in the library. (They are, however, in a different .lib file, and perhaps that improves matters somehow.)

You can download the November 2014 working draft of the current ISO C++ standard here.

like image 87
Harry Johnston Avatar answered Sep 18 '22 12:09

Harry Johnston