Change Preprocessor value in Objective-C

风格不统一 提交于 2019-12-07 21:15:29

问题


Is there any way to change a preprocessor value like:

#define XValue 50 

in Objective-C?


回答1:


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



回答2:


#undef XValue
#define XValue 100



回答3:


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

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