[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with including <unistd.h>

From: Benjamin Lindner
Subject: Re: Problem with including <unistd.h>
Date: Thu, 27 Jan 2011 18:22:53 +0100

> | So currently, it would require unistd.h to be either included twice,
> | or be included before winsock2.h to work properly.
> I think it would be OK if we had to include unistd.h before
> winsock2.h.

I don't agree.

How do you know whether winsock2.h has already been included?
In the current case the inclusion chain is roughly as follows
<string> -> many stages ... -> <cwchar> -> libgnu/wchar.h ->
libgnu/time.h -> pthreads.h -> windows.h -> winsock2.h

So even if you did not explicitly ask for it, it's there. And in this
case the culprit is gnulib itself, who includes pthreads.h from its
time.h subsitute header which eventually includes winsock2.h.

How could you be supposed to know that gcc's <string> leads eventually
to winsock2.h being included?
Or any other header for that matter?

Changing the inclusion order of unistd.h and winsock.h is just one of
the two solutions to work around the aforementioned #if clause, but I
don't think it's a good one.

BTW, the comment in unistd.h reads

   - On mingw, several headers, including <winsock2.h>, include <unistd.h>,

Which is not true as preprocessing a simple file containing
  #include <winsock2.h>
immediately proves.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]