8

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.

harmic
  • 28,606
  • 5
  • 67
  • 91
  • the answer in this thread might help: http://stackoverflow.com/questions/814975/getch-is-deprecated – object Oct 25 '15 at 06:16
  • did you look to this: ISO/IEC 14882:2011(E) ? – HDJEMAI Oct 25 '15 at 06:22
  • 5
    `mkdir` isn't part of the ISO standard, and according to the ISO standard all non-standard functions provided by the runtime library are supposed to start with an underscore. Accordingly, Microsoft have added the underscore to all of the POSIX-like functions (and other non-standard functions) in the runtime library. There's really nothing more to it - only the old function names are deprecated, not the functions themselves, and it only applies to Visual Studio, not to POSIX. – Harry Johnston Oct 25 '15 at 06:42
  • 3
    Posix is difficult, it dumps a lot of short lowercase names in the global namespace. The C language desperately needs namespace support. Only the name is deprecated, not the function. – Hans Passant Oct 25 '15 at 08:17
  • @HocineDJEMAI No, as stated in the question I don't have access to the actual standards, only the freely available WG drafts. – harmic Oct 26 '15 at 02:56
  • @HarryJohnston Your comment is basically what I was looking for, although it would be nice to know which clause of the standard states that. – harmic Oct 26 '15 at 02:58
  • @harmic, you have it here (it's not legal to give you the link i think, but you can take a look): http://vk.com/doc100509572_160085962?hash=6801602629449dfa59&dl=27c32949114b3322a2 – HDJEMAI Oct 26 '15 at 03:05

1 Answers1

6

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.

Harry Johnston
  • 35,639
  • 6
  • 68
  • 158