首先#pragma在本质上是声明,常用的功能就是注释,尤其是给Code分段注释;而且它还有另一个强大的功能是处理编译器警告,但却没有上一个功能用的那么多。

clang diagnostic 是#pragma 第一个常用命令:

#pragma clang diagnostic push

#pragma clang diagnostic ignored "-相关命令"

// 你自己的代码

#pragma clang diagnostic pop

常见的用法

1. 方法弃用告警

1
2
3
4
#pragma clang diagnostic push   
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"  
   //  
#pragma clang diagnostic pop

2. 不兼容指针类型

1
2
3
4
#pragma clang diagnostic push   
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"  
   //  
#pragma clang diagnostic pop

3. 循环引用

1
2
3
4
5
6
7
// completionBlock is manually nilled out in AFURLConnectionOperation to break the retain cycle.  
#pragma clang diagnostic push  
#pragma clang diagnostic ignored "-Warc-retain-cycles" 
    self.completionBlock = ^ {  
        ...  
    };  
#pragma clang diagnostic pop

4. 未使用变量

1
2
3
4
#pragma clang diagnostic push   
#pragma clang diagnostic ignored "-Wunused-variable"  
    int a;   
#pragma clang diagnostic pop

5. 未使用default

1
2
3
4
5
6
7
8
9
10
11
12
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcovered-switch-default"
//    switch (style) {
//        case UITableViewCellStyleDefault:
//        case UITableViewCellStyleValue1:
//        case UITableViewCellStyleValue2:
//        case UITableViewCellStyleSubtitle:
//            // ...
//        default:
//            return;
//    }
#pragma clang diagnostic pop

参考链接:

http://nshipster.cn/pragma/

http://nshipster.com/clang-diagnostics/

http://fuckingclangwarnings.com/

最新文章

  1. jquery 回车事件
  2. ASP.NET 5 单元测试中使用依赖注入
  3. 《BI项目笔记》创建多维数据集Cube(2)
  4. Android 学习第10课,Android的布局
  5. HTTPS实现原理
  6. Spring计划会议内容
  7. 【转载】Apache Kafka:下一代分布式消息系统
  8. 微信 回复多图文 借助php框架
  9. python 3.5 之 单双三引号
  10. swift学习 - 分类(Extensions)
  11. react 监听页面滚动
  12. 在进行多次scanf时,printf输出错误
  13. C#遍历枚举中所有值
  14. centos U盘挂载问题
  15. Lyk Love painting/convex hull/mumsic
  16. [Ramda] Lens in Depth
  17. linux 之sed
  18. gulp 编译es6 探究
  19. Selenium自动化测试基础
  20. 如何编写Makefile?

热门文章

  1. HDU 4320 Arcane Numbers 1(质因子包含)
  2. HDU 4315 Climbing the Hill(阶梯博弈)
  3. form提交不刷新,不跳转页面
  4. 导入dmp文件时,需要删除原有ORACLE数据库实例
  5. python 正则表达式规则收集
  6. Java == 和 equals 区别
  7. Wannafly挑战赛19 B矩阵
  8. python读写json文件(转)
  9. ssh服务及安全配置
  10. ultragrid