Preprocessing

When you invoke cc without options, it initiates a sequence of four basic operations, or stages: preprocessing, compilation, assembly, and linking. In a multifile program, the first three stages are performed on each individual source code file, creating an object code file for each source code file. The final linking stage combines all the object codes that were created by the first three stages, along with user-specified object code that may have been compiled earlier into a single executable image file.

Apple’s compiler provides two preprocessors. The default preprocessor for both C and Objective-C is the precompilation preprocessor written by Apple, named cpp-precomp. The standard GNU C preprocessor, named cpp, is also available and is the default for Objective-C++ code. cpp-precomp supports precompiled header files. (For more information about cpp-precomp, see Chapter 5.) cpp-precomp is faster than cpp. However, some code may not compile with cpp-precomp. In that case, you should invoke cpp by instructing cc not to use cpp-precomp. For example, to compile the C program myprog.c using the standard GNU preprocessor, cpp, use the -no-cpp-precomp switch as follows:

cc -no-cpp-precomp myprog.c

Warning

Earlier versions of the Mac OS X Developer Tools used the -traditional-cpp switch, but this switch had undesirable side effects and is deprecated.

Chapter 5 describes precompilation in more detail.

Get Mac OS X for Unix Geeks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.