Re: [Mingw-users] windows.h dependency
- Date: Sun, 03 Feb 2008 18:37:47 +0200
- From: Roumen Petrov <bugtrack@xxxxxxxxxxxxxxxxx>
- Subject: Re: [Mingw-users] windows.h dependency
NightStrike wrote:
> On 2/3/08, Roumen Petrov <bugtrack@xxxxxxxxxxxxxxxxx> wrote:
>
>> As is pointed before a program may include other header first that
>> include windows.h.
>>
>
> Every header should be protected against multiple inclusion. If it's
> not, that's a bug. The point is that dependencies of a header should
> be resolved by the header, and not the user of the header.
>
>
>> For sockets in particular it is winsock2.h or ws2tcpip.h for winsock 2.
>> If program include windows.h first the result is winsock 1.1.
>> Mingw w32api must not resolve this.
>>
>
> #if defined(__USE_W32_SOCKETS) || !(defined(__CYGWIN__) ||
> defined(__MSYS__) || defined(_UWIN))
>
> #if (_WIN32_WINNT >= 0x0400)
> #include <winsock2.h>
> /*
> * MS likes to include mswsock.h here as well,
> * but that can cause undefined symbols if
> * winsock2.h is included before windows.h
> */
> #else
> #include <winsock.h>
> #endif /* (_WIN32_WINNT >= 0x0400) */
>
>
> Looks like the default is based on the proper criteria, and not a
> blanket "include windows.h, get winsock 1"
>
The /Winsock2.h/ header file internally includes core elements from the
/Windows.h/ header file, so there is not usually an #include line for
the /Windows.h/ header file in Winsock applications. If an #include line
is needed for the /Windows.h/ header file, this should be preceded with
the #define WIN32_LEAN_AND_MEAN macro. For historical reasons, the
/Windows.h/ header defaults to including the /Winsock.h/ header file for
Windows Sockets 1.1. The declarations in the /Winsock.h/ header file
will conflict with the declarations in the /Winsock2.h/ header file
required by Windows Sockets 2.0. The WIN32_LEAN_AND_MEAN macro prevents
the /Winsock.h/ from being included by the /Windows.h/ header.
$ cat test.h
/* #define WIN32_LEAN_AND_MEAN */
#include <windows.h>
#include <winsock2.h>
$ .../bin/i386-mingw32msvc-gcc -E test.h | grep winsock
# 1 ".../i386-mingw32msvc/include/winsock2.h" 1 3
# 17 ".../i386-mingw32msvc/include/winsock2.h" 3
Look like a bug in header in case of mingw.
Roumen
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users