Preprocessor Scope in Precompiled Files

When precompiling a header file, the compiler preprocesses the file too. In other words, a precompiled file is preprocessed in the context of its precompilation, not in the context of its later compilation.

The preprocessor also tracks macros used to guard #include files to reduce parsing time. If a file's contents are surrounded with

#ifndef MYHEADER_H 
  #define MYHEADER_H 
     /* file contents */ 
  #endif
  

the compiler will not load the file twice, saving some time in the process.

Pragma settings inside a precompiled file affect only the source code within that file. The pragma settings for an item declared in a precompiled file (such as data or a function) are saved then restored when the precompiled header file is included.

For example, the source code in Pragma Settings in a Precompiled Header specifies that the variable xxx is a far variable.

Listing 1. Pragma Settings in a Precompiled Header
/* my_pch.pch */

/* Generate a precompiled header named pch.mch. */
#pragma precompile_target "my_pch.mch" 

#pragma far_data on
extern int xxx;

The source code in Pragma Settings in an Included Precompiled File includes the precompiled version of Pragma Settings in a Precompiled Header.

Listing 2. Pragma Settings in an Included Precompiled File
/* test.c */

/* Far data is disabled. */
#pragma far_data off

/* This precompiled file sets far_data on. */
#include "my_pch.mch"   

/* far_data is still off but xxx is still a far variable. */

The pragma setting in the precompiled file is active within the precompiled file, even though the source file including the precompiled file has a different setting.