Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In what conditions should I prefer io.h to windows.h?

I am working on a project related to Systems Programming on Windows. For that I was pointed toward windows.h. Now I have come across io.h. What exactly is the difference between them?

For example, since I am porting an application that has already been deployed on Linux, the file open function is open while on Windows, if I use windows.h, the file open function will be CreateFile, and if I use io.h, it will be _open().

like image 667
user1343318 Avatar asked Nov 18 '13 15:11

user1343318


1 Answers

io.h originally provided access to declarations for the low-level I/O primitives in Unix and associated constants and such. Since quite a bit of code depended on it, many (most?) compilers for other systems provided a header by the same name, and some library functions that worked (at least mostly) like the ones in Unix.

Windows.h is (sort of) a rough analog for Windows--a header that gives access to (declarations for) the functions, constants, etc. for Windows. The big difference is that Windows.h does a lot more than the basic, low-level I/O covered by io.h, instead covering all the GUI functions, etc.

So: if you want to write code that does I/O at a fairly low level on Unix-like systems and can also port to other systems like Windows, you probably want to use io.h. If you want to do system programming specifically for Windows, you almost certainly want to use windows.h.

like image 104
Jerry Coffin Avatar answered Oct 24 '22 05:10

Jerry Coffin