Android12之#pragma clang diagnostic ignored总结(一百六十八)

简介: CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长!

优质专栏:Audio工程师进阶系列原创干货持续更新中……】🚀

人生格言: 人生从来没有捷径,只有行动才是治疗恐惧和懒惰的唯一良药.

更多原创,欢迎关注:Android系统攻城狮

欢迎关注Android系统攻城狮

1.前言

本篇目的:解决Android12编译报错:error: BUILD_COPY_HEADERS is obsolete。

2.`#pragma clang diagnostic push、#pragma clang diagnostic pop、#pragma clang diagnostic ignored "-Wconversion"指令介绍

  1. #pragma clang diagnostic push:将当前的编译器警告和错误状态推入一个堆栈中,以便后续可以通过pop指令还原。

  2. #pragma clang diagnostic pop:将之前保存在堆栈中的编译器警告和错误状态还原,恢复到之前的状态。

  3. #pragma clang diagnostic ignored "-Wconversion":用于忽略编译器对指定的警告类型的警告信息。

3.忽略警告语法介绍

1.忽略警告语法通用语法

#pragma clang diagnostic push
#pragma clang diagnostic ignored “-相关命令”
// 自己的代码
#pragma clang diagnostic pop

2.可以忽略的警告

1.方法弃用警告 “-Wdeprecated-declarations”
2.不兼容指针类型 “-Wincompatible-pointer-types”
3.循环引用警告 “-Warc-retain-cycles”
4.未使用变量警告 “-Wunused-variable”
5.已废弃属性或方法警告"-Wdeprecated-declarations"

4.代码实例

1.忽略隐式类型转换警告

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wconversion"#include <iostream>int main() {int x = 10;short y = x;  // 隐式类型转换,编译器会发出警告std::cout << y << std::endl;return 0;
}#pragma clang diagnostic pop

第一步:#pragma clang diagnostic push将编译器警告状态保存在堆栈中,
第二步:使用#pragma clang diagnostic ignored "-Wconversion"指令忽略了编译器对隐式类型转换的警告。
第三步:使用#pragma clang diagnostic pop恢复了之前的编译器警告状态。

2.忽略未使用函数的警告

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"#include <iostream>void unusedFunction() {std::cout << "This function is unused" << std::endl;
}int main() {std::cout << "Hello, world!" << std::endl;return 0;
}#pragma clang diagnostic pop

3.忽略未初始化变量的警告

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wuninitialized"#include <iostream>int main() {int x;std::cout << x << std::endl; // 未初始化变量,会引起警告return 0;
}#pragma clang diagnostic pop

4.忽略数组越界的警告

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warray-bounds"#include <iostream>int main() {int arr[3] = {1, 2, 3};std::cout << arr[5] << std::endl; // 越界访问数组,会引起警告return 0;
}#pragma clang diagnostic pop

5.忽略未使用参数的警告

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"#include <iostream>void unusedParameter(int x) {std::cout << "This parameter is unused" << std::endl;
}int main() {unusedParameter(10);return 0;
}#pragma clang diagnostic pop

6.忽略未定义行为的警告(例如除以零)

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdiv-by-zero"#include <iostream>int main() {int x = 10;int y = 0;int z = x / y; // 除以零,会引起未定义行为的警告std::cout << z << std::endl;return 0;
}#pragma clang diagnostic pop

7.忽略常量表达式溢出的警告

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wconstant-conversion"#include <iostream>int main() {const int x = 2147483647; // INT_MAXconst int y = x + x; // 常量表达式溢出,会引起警告std::cout << y << std::endl;return 0;
}#pragma clang diagnostic pop

8.忽略未使用的私有成员函数的警告

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"#include <iostream>class MyClass {
private:int unused;void unusedFunction() {std::cout << "This private function is unused" << std::endl;}
};int main() {MyClass obj;return 0;
}#pragma clang diagnostic pop

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/151899.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

基于物联网云平台的分布式光伏监控系统的设计与实现

贾丽丽 安科瑞电气股份有限公司 上海嘉定 201801 摘要&#xff1a;针对国内光伏发电监控系统的研究现状&#xff0c;文中提出了基于云平台的光伏发电监控体系。构建基于B/S架构的数据实时采集与推送&#xff0c;以SSH(strutsspringhibernate)作为Web开发框架&#xff0c;开发基…

windows PC virtualBox 配置

效果&#xff1a; oracle vitualbox 可以访问通PC主机&#xff0c;可以访问外网: 注意&#xff0c;如果docker0网络地址&#xff0c;和PC主机的网络地址冲突了&#xff0c;需要变更docker的网络地址&#xff1a; root/home/mysqlPcap/anti-tamper $ cat /etc/docker/daemon.js…

docker 中给命令起别名

docker 的有些命令特别复杂&#xff0c;我们可以给它设置别名简化输入&#xff0c;就不用每次都输入那么多了&#xff01;&#xff01;&#xff01; 1. 进入 .bashrc 中修改配置&#xff08; .bashrc 是root下的隐藏文件&#xff09; cd /rootvim .bashrc2. 在 .bashrc 中加入…

iOS iGameGuardian修改器检测方案

一直以来&#xff0c;iOS 系统的安全性、稳定性都是其与安卓竞争的主力卖点。这要归功于 iOS 系统独特的闭源生态&#xff0c;应用软件上架会经过严格审核与测试。所以&#xff0c;iOS端的作弊手段&#xff0c;总是在尝试绕过 App Store 的审查。 常见的 iOS 游戏作弊&#xf…

Linux两条服务器实现相互免密登录

1.准备两台虚拟机&#xff0c;一台充当服务器端&#xff08;server&#xff09;&#xff0c;一台充当客户端&#xff08;client&#xff09; 服务器端&#xff08;server&#xff09;&#xff1a;192.168.75.139 客户端&#xff08;client&#xff09;&#xff1a;192.168.75…

Linux中shell脚本中的运算

目录 一、运算符号 二、运算指令 三、练习 一、运算符号 加法-减法*乘法/除法%除法后的余数**乘方自加一--自减一 <小于<小于等于>大于>大于等于等于ji&#xff0c;jji*jj*i/jj/i%jj%i 二、运算指令 (()) ##((a12)) let ##let a12 expr ##expr 1 2 …

[ACTF2020 新生赛]Include 1

题目环境&#xff1a;超链接&#xff0c;点进去看看你能找到flag吗&#xff1f;除了这些网页什么都没有&#xff0c;但是不当紧&#xff0c;因为我们有一双善于发现的眼睛&#x1f440;F12瞅瞅无&#xff0c;并无其他等等URL看了吗&#xff1f;发现存在一个参数file&#xff0c…

[数据结构】二叉树

1.概念 一棵二叉树是结点的一个有限集合&#xff0c;该集合&#xff1a; 1. 或者为空 2. 或者是由一个根节点加上两棵别称为左子树和右子树的二叉树组成 从上图我们可以发现&#xff1a; 1.二叉树不存在大于2 的度 2.二叉树的子树有左右之分&#xff0c;次序不能颠倒。是有…

C++之左值、右值、std::forward、std::move总结(二百五十)

简介&#xff1a; CSDN博客专家&#xff0c;专注Android/Linux系统&#xff0c;分享多mic语音方案、音视频、编解码等技术&#xff0c;与大家一起成长&#xff01; 优质专栏&#xff1a;Audio工程师进阶系列【原创干货持续更新中……】&#x1f680; 人生格言&#xff1a; 人生…

走进人工智能的大门:打造职业梦想的契机

在当今数字化时代&#xff0c;人工智能&#xff08;AI&#xff09;不再是科幻小说的情节&#xff0c;而是我们现实生活和职业生涯中的现实部分。从自动驾驶汽车到智能助手&#xff0c;AI 的影响已经渗透到各个领域。而中国&#xff0c;作为全球人工智能市场的重要一员&#xff…

React之服务端渲染

一、是什么 在SSR中 (opens new window)&#xff0c;我们了解到Server-Side Rendering &#xff0c;简称SSR&#xff0c;意为服务端渲染 指由服务侧完成页面的 HTML 结构拼接的页面处理技术&#xff0c;发送到浏览器&#xff0c;然后为其绑定状态与事件&#xff0c;成为完全可…

SpringBoot | SpringBoot中实现“微信支付“

SpringBoot中实现"微信支付": 1.“微信支付”产品2."微信支付"接入流程3.“微信小程序支付”时序图&#xff1a;3.1 “商家端JSAPI下单” 接口3.2 “微信小程序端调起支付” 接口 4.微信支付准备工作&#xff1a;4.1 获得微信支付平台证书、商户私钥文件4…