开发者

Does something happen different in the compiler between these two ways of including the same headers?

Does:

#include <vector>
#include <string>
#include <winsock开发者_如何学编程2.h>  
#include <iphlpapi.h>
#include "FileX.h" <--------------which #include <windows.h>

Compile the same as in one header file:

#include <vector>
#include <string>
#include <winsock2.h>  
#include <iphlpapi.h>
#include <windows.h>

In the first case, the windows.h is another file (still included last).

Does something happen different in the compiler between these two ways of including the same headers?


In my world, "FileX.h" is defined as follows

#error "This is different from windows.h, as it contains an #error!"
#include <windows.h>

So yes, there "Does something happen different in the compiler" in this case.

Even if it is simply defined as follows, things may be different

#include <windows.h>

If you include too many headers, you may hit the compiler's resource limit earlier than if you included <windows.h> directly, and it may hit different paths that may hit different errors in your compiler etc...

So it really depends on what you mean by "Does something different in the compiler" at all.


Unless FileX.h does something weird (e.g. #ifdefs, or #pragmas) before it does the #include <windows.h>, then these should be identical.


It depends on what compiler you use. Usually the "" variant starts looking for the header in the directory of the file including it. The <> include goes directly to the system headers.

The language standard just says that it is implementation defined.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜