views:

226

answers:

1

Why are the API's _open, _close, and other standard file i/o functions prefixed with an underscore? Aren't these part of some standard?

A: 

open/close are part of some Unix standards, POSIX, SUS, etc. but Windows is not a Unix. You'll note that the ANSI C standard library functions like fopen do not have the single underscore decoration.

Because Windows isn't a Unix, there may have been a time, long ago, where the Unix style APIs were not available. Because of this, client code could have been written that defined functions like open and close. To maintain compatibility with existing code, when Unix style APIs were added, they could be added with leading underscores because identifiers with leading underscores are reserved for the implementation. In other words, no existing code should be defining a function named _open.

"Portable" code targetting the Unix style apis can then be relatively easily compiled via use of macros (or aliases implemented at the linker level), since that code, targetting unix, knows it didn't define any functions named open/close etc.

Logan Capaldo