3

I would like to 'turn off' the compiler for a section of my code. I do not want to use comments to 'hide' the code from the compiler because there are a lot of /*...*/ comments embedded in this section. I would guess that there is a common way to use compiler directives or #defines or something to control the compilation. In fact my desire to suppress compilation is not dependent on a condition like the SDK or the platform, I would just like to turn it off. How does one accomplish this?

0

2 Answers 2

6

A quick fix is to wrap that section of code with

#if 0
…
#endif

where 0 means false. To enable it again,

#if 1
…
#endif

Another option is to define a macro (Project Info -> Build -> Preprocessor macros) and define it when you want to disable that code, and undefine it when you want to enable that code. For instance,

#ifndef IGNORE_THIS_SECTION
…
#endif

You can achieve a similar, ‘inverse’ effect by using #ifdef instead.

Sign up to request clarification or add additional context in comments.

Comments

2

You could create a preprocessor flag that is checked at compile time. I use this for multiple targets.

Step 3 Writing Preprocessor Codes, of this tutorial for creating multiple targets:

http://just2us.com/2009/07/tutorial-creating-multiple-targets-for-xcode-iphone-projects/

tells you how to create a flag and use the #if conditional compile.

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.