Gabrail
Gabrail

Reputation: 220

Change Preprocessor value in Objective-C

Is there any way to change a preprocessor value like:

#define XValue 50 

in Objective-C?

Upvotes: 2

Views: 2119

Answers (3)

Steve Jessop
Steve Jessop

Reputation: 279415

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.

Upvotes: 1

JeremyP
JeremyP

Reputation: 86691

#undef XValue
#define XValue 100

Upvotes: 2

MByD
MByD

Reputation: 137442

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

Upvotes: 5

Related Questions