MSVC _open / _close / etc

Why are the _open, _close, and other standard file I / O functions prefixed with an underscore? Isn't this part standard?

+2


source to share


1 answer


open / close are part of some Unix, POSIX, SUS, etc. standards, but Windows is not Unix. You will notice that the ANSI C standard library like fopen does not have a single underscore.

Since Windows is not Unix, there may have been a long time ago when Unix APIs were not available. Because of this, client code could be written to open and close certain functions. To maintain compatibility with existing code, when Unix APIs were added, they could be added using leading underscores, since identifiers with leading underscores are reserved for implementation. In other words, no existing code should define a function named _open.



"Portable" code targeting the Unix apis style can be relatively easily compiled using macros (or linker-level aliases), since this unix targeting code knows that it did not define any functions named open / close, etc.

+2


source







All Articles