目标C-如何编写宏 [英] Objective C - How to write a macro

查看:69
本文介绍了目标C-如何编写宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要写多行宏.我需要这个,因为我必须有部分代码已经被粘贴"到具体的点在我的代码.我该怎么办?

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?

推荐答案

这不是真的从你的问题明确你真正想要的东西,而是一个普通的多行的宏定义如下:

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)

这篇关于目标C-如何编写宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆