14

Is there a way to get pre-processed C/Objective-C code? I have some files I acquired and would like to see the code produced by some #defines.

4 Answers 4

23

From within Xcode:

  • Xcode 3: Select the file, then Build → Preprocess.
  • Xcode 4: Select the file, then Product → Generate Output → Generate Preprocessed File.
Sign up to request clarification or add additional context in comments.

1 Comment

Just a note - When you generate the preprocessed file this way, there is a whole lot of other code from the files that were #imported. The file you really want to see is at the very bottom of the output.
17

On the command line, gcc -E foo.m will show you the preprocessed output (just as it does for normal C/C++ files). Of course, this will also expand any #include or #import statements you may have in your code.

Comments

7

Use the -E command-line argument to gcc or clang. This is documented as: “Preprocess only; do not compile, assemble or link” and indeed it outputs the preprocessed version to stdout.

Comments

3

In Xcode 5: Select the .m file, then Product -> Perform Action -> Preprocess ".m"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.