[RFC] io.h & friends

Dan Kegel dank at kegel.com
Thu Jan 9 09:50:14 CST 2003


Dimitrie O. Paun wrote:
> #if !defined(__UNIX__) || defined(USE_MSVCRT)
> #include <io.h>
> #endif
> 
> But this is not all! For example, wxWindows includes stuff like this:
> #include <sys/unistd.h>
> #include <sys/stat.h>
> Since they are available in mingw, and cygwin, and in UNIX, but if
> I want to use msvcrt they conflit with stuff from there!
> 
> It's a mess. As you can see, the defines alone can make a grown man
> cry, and this is for a simple include. And I don't even know I've
> covered all the basis! Problem is that there are already 5 platforms:
> UNIX, Wine, Cygwin, MinGW, MS. And complexity grows exponentially
> with the number of platforms and combinations you have to test for.
> 
> This way lays madness. It is now clear to me why the Cygwin people
> included io.h. It's so that you can compile with or without the
> -mno-cygwin switch, and have everything work. The only way for that
> to happen without ungodly defines and tests, is to have a flat space
> of include files: a union of MS & Unix files. Even if they are
> empty! This way you can simply do:
> 
> #include <unistd.h>
> #include <io.h>

Applications that use autoconf surround each #include with a test for that header's presence, e.g.

#if HAVE_IO_H
#include <io.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif

That's best practice when writing applications.

When creating a platform, on the other hand, it's probably
best practice to have all those headers, even if they're empty,
so everyone can #include them without worrying about the #if HAVE_BLAH_H's.
- Dan

-- 
Dan Kegel
Linux User #78045
http://www.kegel.com




More information about the wine-devel mailing list