美文网首页
# define 与 undef

# define 与 undef

作者: youngyunxing | 来源:发表于2016-07-21 12:38 被阅读126次

define

  • 宏替换,编译阶段将前面的宏用后面的值替换掉,用法如下

  • 替换常量,方便修改

#define PI 3.14
NSLog(@"%f",PI);

  • 替换函数或者方法
#define RGB(r,g,b,a)  [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
self.view.backgroundColor = RGB(255, 0, 0, 1.0);

undef

  • 取消宏定义,取消前面已经定义过的宏,使其失效,如果之前没有定义,则不做任何处理
#define PI 3.14
#undef  PI

编译报错:

Paste_Image.png

相关文章

网友评论

      本文标题:# define 与 undef

      本文链接:https://www.haomeiwen.com/subject/lrsbjttx.html