Is there any way to change a preprocessor value like:
#define XValue 50
in Objective-C?
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
#undef XValue
#define XValue 100
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.
来源:https://stackoverflow.com/questions/11949052/change-preprocessor-value-in-objective-c