A pragma statement is a directive for providing additional information to the preprocessor or compiler beyond what is conveyed in the language itself. There are a small number of pragma types defined by the C standard; individual compilers may support any number of additional types and values.
The CodeWarrior compiler supports a number of pragmas, including pragma equivalents for most of the compiler settings you can set in the user interface. It also supports some pragmas you can’t set in the user interface. Some examples of pragmas CodeWarrior supports are #pragma unused and #pragma once. In CodeWarrior, pragmas can turn a feature on and off within an individual compilation unit. For example, you can use the pragma statements #pragma export on and #pragma export off in a source file to bracket any symbols you want to export from a shared library.
Xcode supports some CodeWarrior-defined pragmas. However, Xcode supplies build settings for many of the features the CodeWarrior compiler supports through pragmas. These settings should be set automatically when you import a CodeWarrior project, but you can also add, delete, or modify build settings. Figure 1-3 shows some of the Language settings you can set for a target in the Build pane in an inspector window in Xcode.
Note: When a file is compiled, build settings are passed to the compiler as command line flags. If a GCC compiler option is not available in the Xcode user interface, you can set individual flags with the Other C Flags setting.
Although language settings can be set on a file, target, or project basis, you cannot use them for inline control of compiler options. As a result, the smallest unit for which you can set a compiler option is a single source file. To modify build settings on a target-wide basis, select the target in the Groups & Files list and open an Info window (by clicking the Info button or by choosing File > Get Info). Select the Build pane, then make your changes.
Note: You also modify the settings in an inspector window, which you open by holding the Option key and choosing File > Show Inspector.
Xcode provides a different interface for modifying options for a single file (or several files). You can add additional compiler flags for one or more files with the following steps:
Open the target in the Groups & Files list.
Open the Compile Sources build phase.
Select the file (or files) for which you want to modify the settings.
Open an Info window by choosing File > Get Info.
Select the Build pane (shown in Figure 1-4 for a multiple selection).
Add any desired compiler flags. Multiple flags should be separated by spaces.
If your CodeWarrior project follows the common pattern of placing pragmas in a header file that is included by other source files, you won’t have to make changes to individual files—you can just set the corresponding values for an entire target or a subset of files. However, if you have code that uses pragmas to turn settings on and off within a single file, and if you need to maintain that level of control, you may need to break up some files so that code that shares common build settings is in one file.
For additional information on modifying your source files, see “Maintaining Parallel Projects in Xcode and CodeWarrior.” For information on using pragmas with respect to identifying export symbols, see “Exporting Symbols.”
For further information on setting per-target and per-file compiler options in Xcode, see Build Settings in Xcode User Guide. For a list of pragmas supported by GCC, see the sections "Pragmas" in GNU C 4.0 Preprocessor User Guide and "Pragmas Accepted by GCC" in GNU C/C++/Objective-C 4.0.1 Compiler User Guide.
For more information on code changes you may need to make as a result of pragma statements in your CodeWarrior code, see “Create a Prefix File for PowerPlant.”
Last updated: 2006-10-26