Change Preprocessor value in Objective-C

最后都变了- 提交于 2019-12-06 08:27:38

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!