1

I have a project with some macros that are defined using Objective-C statements, like this:

#define TEST [someObject someNumber] == 500

I need to define another value based on this result, like this:

#if TEST
  #define THING = 1
#else
  #define THING = 2
#endif

But, this doesn't work. And I can't use #ifdef TEST because the value is always defined. Even if it's false, it's still defined.

TEST is based on an ObjC statement, and it seems like the preprocessor has no way of evaluating it. So, is there no way to test for this?

4
  • Can the preprocessor know the value of [someObject someNumber] at runtime? Commented Dec 5, 2016 at 11:58
  • Can the preprocessor know the value of [someObject someNumber] at buildtime? Commented Dec 5, 2016 at 12:07
  • Maybe. Once runtime starts, it should know the value. If it does, how would I know? And how would I use it? Commented Dec 5, 2016 at 12:50
  • 2
    The more I think about it, the more I think this is a dumb question. Since TEST must be evaluated during runtime, there's no way to know the value of it during build time. Because the preprocessor can't know the value, it can't test it. Is this correct? Commented Dec 5, 2016 at 13:06

1 Answer 1

1

In the comments you wrote:

Since TEST must be evaluated during runtime, there's no way to know the value of it during build time. Because the preprocessor can't know the value, it can't test it. Is this correct?

Yes.

The preprocessor runs (at least logically) before the rest of the compiler. It is essentially language and syntax agnostic, and does not even have access to constants defined in your code. The conditional constructs operate solely with preprocessor tokens.

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

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.