I have read somewhere, it says that include file hierarchy/position matters.
For example, #include <Winsock2.h> before #include <iphlpapi.h>.
I would really appreciate if someone could explain this to me. Thank you.
I have read somewhere, it says that include file hierarchy/position matters.
For example, #include <Winsock2.h> before #include <iphlpapi.h>.
I would really appreciate if someone could explain this to me. Thank you.
It shouldn't, but in practice it can matter if the header file author made some assumptions that other header files would be included first, or if a header tile declares things like macros which may change the meaning of code that follows.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Sometimes one header relies upon definitions in a different header. In large systems situations like that do arrise.
Thank you for answering.
Let's say i have 2 headers.
winsock.h and winsock2.h
I include winsock2.h first then only winsock.h. Both of then contain a function named sockfoo() which were defined differently. In this case, which function will be chosen when I call sockfoo() in main(). Is it sockfoo() from winsock.h or winsock2.h ?
Depends on the Compiler/Header files; in this case I think the first one include is used on certain MinGW GCC Compilers.
How it is sometimes done on MinGW GCC, the header guard for winsock2 declares the header guard for both winsock.h and winsock2.h; never really checked what winsock.h declares.
http://en.wikipedia.org/wiki/Include_guard
Tim S.
Last edited by stahta01; 07-22-2011 at 06:43 AM.
I know it's only an example but you should not need to include both winsock2 and winsock, since winsock2 includes winsock for you.
The easiest way to track this stuff down is to open the header files in a text editor (NOT a word processor) and have a look for yourself.
Where is the location of the header files (ie. winsock.h) in MS visual studio 2008?
If you have your project open in Visual Studio 2008 and you want to see what is in the header files, just right click on the header in the source and a window will pop-up. The first option in that pop-up will say "Open Document <iomanip>" as an example. Choosing that option will open that particular header file in another tab of the IDE so you can see what it contains. No need to go searching for the actual folder where it is located just to view its contents.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens