Examples of Using Compiler Options and #pragma hdrfile

The following examples show the interaction of options and #pragma hdrfile directives:

Example 1

#pragma hdrfile "fred.pch"
#include "h1.h"
#include "h2.h"
main () {}
Options Specified Behavior
/Fi+ /Si+ The headers "h1.h" and "h2.h" are precompiled using the file "fred.pch"
/Fidave.pch The compiler ignores the name specified with the option, because it is in conflict with the #pragma hdrfile directive. The compiler generates new headers in "fred.pch", but does not use them.

Example 2

#pragma hdrfile "fred.pch"
#include "h1.h"
#pragma hdrstop
#include "h2.h"
main () {}
Options Specified Behavior
/Fi+ /Si+ Only the header "h1.h" is precompiled, using the file
"fred.pch"
/Sidave.pch
The compiler ignores the name specified with the option, because it is in conflict with the #pragma hdrfile directive. The compiler looks for the precompiled headers in "fred.pch", but does not generate new headers.

Example 3

#include "h1.h"
#pragma hdrstop
#include "h2.h"
main () {}

 

Options Specified Behavior
/Fi+ /Si+
Only the header "h1.h" is precompiled, using the file "csetc.pch" (for a C file) or "csetcpp.pch" (for a C++ file)
/Sidave.pch
/Fijohn.pch
The compiler ignores the name specified with /Si, and uses the file "john.pch", which is specified later. The compiler looks for precompiled headers in "john.pch" and regenerates them if they are not found or are out of date.

Example 4

#pragma hdrstop
#include "h1.h"
main () {}
Options Specified Behavior
Any options No headers are precompiled, because there is no initial sequence: #pragma hdrstop occurs before the first include directive.


Precompiled Headers


Create Precompiled Header Files