DesirePRG
DesirePRG

Reputation: 6388

#include "windows.h" how does it work

When I include "windows.h" in a c program in the following manner

#include "windows.h"

it compiles fine. According to my knowledge if we include a header file with "" the compiler would search for header files in the current directory. Then how does my program compile without a header file as such?

Upvotes: 1

Views: 13277

Answers (1)

David Heffernan
David Heffernan

Reputation: 613322

The treatment of the quoted form of #include is implementation-defined. The standard (ISO/IEC 9899:201x, 6.10.2.3) says, with my emphasis:

A preprocessing directive of the form

# include "q-char-sequence" new-line

causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read

# include <h-char-sequence> new-line

with the identical contained sequence (including > characters, if any) from the original directive.

So to answer the question you need to refer to the documentation of your compiler.

For the sake of argument and illustration, let's assume that you use the MS compiler, since you did not specify which compiler you use. The documentation for the MS compiler says, for the quoted form of #include:

The preprocessor searches for include files in the following order:

  1. In the same directory as the file that contains the #include statement.
  2. In the directories of any previously opened include files in the reverse order in which they were opened. The search starts from the directory of the include file that was opened last and continues through the directory of the include file that was opened first.
  3. Along the path specified by each /I compiler option.
  4. Along the paths specified by the INCLUDE environment variable.

If you are using a different compiler then you will need to refer to the documentation for your compiler.

Upvotes: 5

Related Questions