7

A macro is a preprocessor right. Sometimes we set things right sometimes we don't.

Wouldn't it be nice to once in a while expand the macro and see how it works?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user4951
  • 32,206
  • 53
  • 172
  • 282
  • A macro isn't a preprocessor - it's a source code construct which is processed by a program or part of a program known as a preprocessor. Also, what version of Xcode are you using ? – Paul R Sep 30 '11 at 06:55
  • possible duplicate of [Xcode 4 preprocessor output](http://stackoverflow.com/questions/5937031/xcode-4-preprocessor-output) – Paul R Sep 30 '11 at 06:59

1 Answers1

13

You can do this with most compilers, e.g. with gcc:

$ gcc -E

this just runs the preprocessor and then stops, giving you the pre-processed output on stdout.

If you're using Xcode though you don't even need to do this - depending on what version of Xcode you're using you can just select Preprocess from the Build menu (that's what its called in Xcode 3.x - if you're using Xcode 4 it may have been moved/renamed). See: Xcode Preprocessor Output

Community
  • 1
  • 1
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • 1
    Unfortunately it looks like the XCode Preprocess function only works if your code builds properly. Which makes it next to useless for debugging macros that aren't compiling. – aardvarkk Jan 18 '16 at 18:49
  • I just tried this with Xcode 7.2 and it seems that compile/link errors don't prevent you from generating preprocessor output - I expect it's only preprocessor errors which (not surprisingly) cause a problem ? – Paul R Jan 18 '16 at 19:13
  • You're correct. It makes sense that there's a distinction, I was just bundling it all together into "build errors", which isn't specific enough. I was hoping to gain some insight into *why* my preprocessor define was messing up by looking at the preprocessor output, but because I had an error in it I wasn't able to see anything other than an error stating that the macro "could not be expanded". – aardvarkk Jan 18 '16 at 19:23
  • 1
    Yes, I think when you have problems at the preprocessor level then you have to resort to something like a "divide and conquer' approach to isolate the problem. – Paul R Jan 18 '16 at 20:53