2

Is there any way to change a preprocessor value like:

#define XValue 50 

in Objective-C?

3 Answers 3

5

If you mean changing it during runtime, then no, as XValue is replaced with 50 before compilation.

If you mean changing it in the compilation, then yes, using #undef and #define.

Example:

XValue = 30; // NOT ALLOWED

#undef XValue // ALLOWED
#define XValue 30
Sign up to request clarification or add additional context in comments.

1 Comment

i mean during runtime .. anyway thanks so much and i will make your answer acceptable
2
#undef XValue
#define XValue 100

Comments

1

What about:

int global_mutable_value = 50; 
#define XValue global_mutable_value

Or just

int XValue = 50;

You don't say why you want XValue to be a macro, so we can't tell whether your intentions for it would be satisfied by something that can change at runtime. If they would, use something that can change at runtime instead of a macro (I've used an extern variable). If they wouldn't, then of course you're out of luck.

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.