For Programmers: Free Programming Magazines  


Home > Archive > VC STL > January 2006 > include header problem?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author include header problem?
paul

2006-01-09, 11:10 pm

Hi,

I have a problem with header file included in my project under windows.

As you know, in ws2tcpip.h, IP_ADD_MEMBERSHIP is defined as 12, however,
in winsock.h (which is included in windows.h) this value is 5. So when I
include
ws2tcpip.h and windows.h in my project, why isn't there any warning for
macro redefinition?

Here is the code:

#include <stdafx.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>

int main()
{
int add_member = IP_ADD_MEMBERSHIP;
....

}

there is no warning during compiling. and the value add_member is 12;
however, if I didn't include <ws2tcpip.h> and there is no problem
of compilation, and the value of add_member is 5;

Can anybody help me how to understand that? Maybe it is a stupid question
for you, but I am bit of lost. Thanks for your reply.




Simon Trew

2006-01-09, 11:10 pm

"paul" <paul.li@digital-rapids.com> wrote in message
news:uzfBBg0BGHA.3876@tk2msftngp13.phx.gbl...
> Hi,
>
> I have a problem with header file included in my project under windows.
>
> As you know, in ws2tcpip.h, IP_ADD_MEMBERSHIP is defined as 12, however,
> in winsock.h (which is included in windows.h) this value is 5. So when I
> include
> ws2tcpip.h and windows.h in my project, why isn't there any warning for
> macro redefinition?
>
> Here is the code:
>
> #include <stdafx.h>
> #include <winsock2.h>
> #include <ws2tcpip.h>
> #include <windows.h>
>
> int main()
> {
> int add_member = IP_ADD_MEMBERSHIP;
> ....
>
> }


....but you're not including winsock.h, you're including winsock2.h. At the
top of winsock2.h we see:

#define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */

And indeed, this does prevent its inclusion (or at least it having any
effect). So there's no multiple definition.

S.


paul

2006-01-09, 11:10 pm

Thank you, Simon!
"Simon Trew" <noneofyour@business.guv> wrote in message
news:OyGRHfFEGHA.3468@TK2MSFTNGP15.phx.gbl...
> "paul" <paul.li@digital-rapids.com> wrote in message
> news:uzfBBg0BGHA.3876@tk2msftngp13.phx.gbl...
>
> ...but you're not including winsock.h, you're including winsock2.h. At the
> top of winsock2.h we see:
>
> #define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */
>
> And indeed, this does prevent its inclusion (or at least it having any
> effect). So there's no multiple definition.
>
> S.
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com