Objective C - How to write a macro

不羁的心 提交于 2019-12-12 13:12:12

问题


I need to write a multi-line macro. I need this because I must have partial code that has been "paste" into specific points in my code. How can I do this?


回答1:


It's not really clear from your question what you actually want, but a plain multi-line macro is defined as follows:

#define FOO something; \
            something_else;

Of course, beware of the if .. else problem. If this is applicable to your case, you could wrap things into a do { ... } while(0) construct. This will ensure that it's treated as a single statement.

#define FOO do                 \
            {                  \
               something;      \
               something_else; \
            } while (0)



回答2:


Use the backslash character like in C.

#define NINE (3 \
  + 3)



回答3:


as in ansi c: http://www.java2s.com/Code/C/Macro-Preprocessor/Definingamacrotocomparetwovalues.htm



来源:https://stackoverflow.com/questions/5715021/objective-c-how-to-write-a-macro

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