Pragma Scope in Precompiled Files

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

For example, the source code in Listing 5.3 specifies that the variable xxx is a far variable.

Listing 5.3 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 Listing 5.4 includes the precompiled version of Listing 5.3.

Listing 5.4 Pragma Settings in an Included Precompiled File

// test.c
#pragma far_data off // far data is disabled
#include "my_pch.mch" // this precompiled file sets far_data on
// 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.