The hdrstop pragma gives you additional control over precompilation filenames and over the place at which the compilation state is saved. The syntax of the hdrstop pragma is
#pragma hdrstop [[("filename")]]
where filename is the name of the precompiled header file to use or create (depending on compilation options). If the filename does not contain a path specification, the precompiled header file is assumed to be in the current directory.
Note that the filename specified in the hdrstop pragma is a string and is therefore subject to the constraints of any C or C++ string. In particular, you must escape backslashes (\) when specifying paths. For example,
#pragma hdrstop( "c:\\c700\\include\\myinc.pch" )
You can also use preprocessing commands to perform macro replacement as follows:
#define INCLUDE_PATH "c:\\c700\\include\\"
#define PCH_FNAME "PROG.PCH"
.
.
.
#pragma hdrstop( INCLUDE_PATH PCH_FNAME )
The hdrstop pragma is ignored unless either the /Yu or /Yc compiler option is specified without a filename.
Placement of the hdrstop Pragma
The following rules govern where the hdrstop pragma can be placed:
It must appear outside any data or function declaration or definition.
It must be specified in the base file, not in any headers.
Consider the following example:
#include <windows.h> // Include several files
#include "myhdr.h"
__inline Disp( char *szToDisplay ) // Define an inline function
{
... // Some code to display string
}
#pragma hdrstop
Summary: The precompilation facility saves the state of the current compilation.
In this example, the hdrstop pragma appears after two files have been included and an inline function has been defined. This might, at first, seem to be an odd placement for the pragma. Consider, however, that the precompilation facility saves the state of the current compilation, not an arbitrary symbol set for a given header file. The correspondence is between source files and precompiled header files, not between header files and precompiled header files.
Note:
If neither the compilation option nor the hdrstop pragma specifies a filename, the base name of the source file is used.
A base file can contain as many as two hdrstop pragmas. You might do this when compiling with both /Yu and /Yc in order to build one .PCH file from another. In such a case, the first hdrstop is associated with a use (/Yu) and the second with the creation (/Yc). If you're building one .PCH file from another, take care to avoid unwanted conflicts between .PCH filenames.