Seeing Preprocessor Output

Sometimes you get an inscrutable error and have no idea why the compiler is complaining. Or you may have code that looks reasonable and compiles OK, but it behaves in a way that defies sanity even when you take the phase of the moon into account. This is a good time to examine the preprocessor’s output so you can see exactly what the compiler is seeing. The -E flag tells gcc to send the preprocessed source code to standard out. You can use Xcode 3’s Preprocess command as well, or Xcode 4’s generated output.

Example 2.2 looks simple enough. It will read a line from standard in and print it back out.

Example 2.2. preprocTest.m

/​/​ ​p​r​e​p​r​o​c​T​e​s​t​.​m​ ​-​-​ ​a​ ​p​r​o​g​r​a​m​ ​t​o​ ​s​h​o​w​ ​p​r​e​p​r​o​c​e​s​s​o​r​ ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide 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.