首先#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/

#pragma 处理警告 clang diagnostic 的使用的更多相关文章

  1. clang和gcc消除警告

    1. clang命令,它的作用是用来消除特定区域的clang的编译警告,-Wgnu则是消除?:警告, 例: #pragma clang diagnostic push #pragma clang di ...

  2. pragma警告处理

    使用pragma消除警告 (绝不可强行消除,因为有可能是个运行时错误) #pragma clang diagnostic push #pragma clang diagnostic ignored & ...

  3. iOS编程 手动忽略clang编译器警告

    在iOS开发过程中, 我们可能会碰到一些系统方法弃用, weak.循环引用.不能运行之类的警告. 有代码洁癖的孩子们非常想消除他们, 今天就让我们来一次Fuck 警告.! 首先学会主要的语句 #pra ...

  4. 预处理指令#pragma

    #pragma介绍 #pragma是一个预处理指令,pragma的中文意思是『编译指示』.它不是Objective-C中独有的东西(貌似在C/C++中使用比较多),最开始的设计初衷是为了保证代码在不同 ...

  5. iOS警告收录及科学快速的消除方法

    来自: http://www.cnblogs.com/dsxniubility/p/4757760.html iOS警告收录及科学快速的消除方法     前言:现在你维护的项目有多少警告?看着几百条警 ...

  6. xcode 消除警告

    项目中引用大量的第三方代码时,这些代码很复杂,不要轻易去改动它,如果编译产生很多警告,该如何消除呢? 1. 最直接.最一劳永逸.最安全的方式,直接找到警告的那段代码,改为不警告.这个方式最安全. 可是 ...

  7. 关于 Pragma 的使用总结

    注意:此文乃是本人阅读多个博客文章后,记下的个人认为重点的地方. 参考文章: 参考1   参考2 #Pragma mark - 用于分离类中的不同功能的方法.(例如,一个 viewController ...

  8. iOS XCode启用/关闭Clang Warnings

    前言:warnings是编码中很重要的一个环节,编译器给出合理的warning能帮助开发者找到自己代码的问题,防止很多bug产生.  默认用XCode创建一个工程,会自动开启一些重要的warnings ...

  9. 你可能不知道的iOS冷知识——#pragma

    Mattt Thompson撰写. Zihan Xu翻译. 发布于2012年10月1日 #pragma 声明是彰显 Objective-C 工艺的标志之一.虽然 #pragma 最初的目的是为了使得源 ...

随机推荐

  1. 在GeoServer里设置图层的默认自定义样式,出现不显示预览图的情况(不起作用)

    在GeoServer里设置图层的默认自定义样式 点击"Layers-->world:country"图层,点击"Publishing"标签,在下面的&qu ...

  2. mathType换行等号对齐

    例如: 输入步骤: (1) (2) (3) (4) 事实上,[ctrl+;]表示的是插入了一个对齐标记符.

  3. SpringBoot整合Graylog3.0

    Graylog简介 Graylog是一个开源的完整的日志管理工具,功能和ELK类似,安装部署更方便. 官方网站 https://www.graylog.org 搭建 使用docker快速搭建 参考 h ...

  4. leecode第七十八题(子集)

    class Solution { public: vector<vector<int>> subsets(vector<int>& nums) { vect ...

  5. 推送消息 web push notification

    参考 : https://developers.google.com/web/fundamentals/engage-and-retain/push-notifications/   ( step b ...

  6. 2d游戏和 3d游戏的区别

    2D游戏和3D游戏的主要区别 一.总结 一句话总结:2D中的单位就是贴图,3D中的单位还有高 1. 3D 和 2D 游戏的区别主要体现在呈现画面和文件体积上: 2. 借助 3D 引擎可以提升 2D 游 ...

  7. English trip EM2-LP-6A Teacher:Julia

    课上内容(Lesson) How many children are in the family? there are 16 kids How old is the oldest child? He' ...

  8. English trip M1 - AC1 My Dream Car Teacher:Corrine

    In this lesson you will learn to describe an object. 课上内容(Lesson) You want to rent a car. Go to the ...

  9. C#使用 System.Net.Mail发送邮件功能

    .NET 里包含了很多很丰富的邮件发送与接受的API在 System.Net.Mail命名空间里,使得我们开发发送和接受邮件相关功能变得简单,下面是一个简单发送邮件的功能: private void ...

  10. java,数字,字符,字符串之间的转化

    首先,先看一道编程题目: A除以B (20) 时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小) 题目描述 本题要求计算A/B ...