GCC 消除编译器的特定警告

2023-05-16

GCC allows the user to selectively enable or disable certain types of diagnostics, and change the kind of the diagnostic. For example, a project’s policy might require that all sources compile with -Werror but certain files might have exceptions allowing specific types of warnings. Or, a project might selectively enable diagnostics and treat them as errors depending on which preprocessor macros are defined.

pragma GCC diagnostic kind option

Modifies the disposition of a diagnostic. Note that not all diagnostics are modifiable; at the moment only warnings (normally controlled by ‘-W…’) can be controlled, and not all of them. Use -fdiagnostics-show-option to determine which diagnostics are controllable and which option controls them.

kind is ‘error’ to treat this diagnostic as an error, ‘warning’ to treat it like a warning (even if -Werror is in effect), or ‘ignored’ if the diagnostic is to be ignored. option is a double quoted string that matches the command-line option.

pragma GCC diagnostic warning "-Wformat"

pragma GCC diagnostic error "-Wformat"

pragma GCC diagnostic ignored "-Wformat"

Note that these pragmas override any command-line options. GCC keeps track of the location of each pragma, and issues diagnostics according to the state as of that point in the source file. Thus, pragmas occurring after a line do not affect diagnostics caused by that line.

pragma GCC diagnostic push

pragma GCC diagnostic pop

Causes GCC to remember the state of the diagnostics as of each push, and restore to that point at each pop. If a pop has no matching push, the command-line options are restored.

pragma GCC diagnostic error "-Wuninitialized"

foo(a); /* error is given for this one */

pragma GCC diagnostic push

pragma GCC diagnostic ignored "-Wuninitialized"

foo(b); /* no diagnostic for this one */

pragma GCC diagnostic pop

foo(c); /* error is given for this one */

pragma GCC diagnostic pop

foo(d); /* depends on command-line options */
GCC also offers a simple mechanism for printing messages during compilation.

pragma message string

Prints string as a compiler message on compilation. The message is informational only, and is neither a compilation warning nor an error. Newlines can be included in the string by using the ‘\n’ escape sequence.

pragma message "Compiling " FILE "..."

string may be parenthesized, and is printed with location information. For example,

define DO_PRAGMA(x) _Pragma (#x)

define TODO(x) DO_PRAGMA(message ("TODO - " #x))

TODO(Remember to fix this)
prints ‘/tmp/file.c:4: note: #pragma message: TODO - Remember to fix this’.

pragma GCC error message

Generates an error message. This pragma is considered to indicate an error in the compilation, and it will be treated as such.

Newlines can be included in the string by using the ‘\n’ escape sequence. They will be displayed as newlines even if the -fmessage-length option is set to zero.

The error is only generated if the pragma is present in the code after pre-processing has been completed. It does not matter however if the code containing the pragma is unreachable:

if 0

pragma GCC error "this error is not seen"

endif

void foo (void)
{
return;

pragma GCC error "this error is seen"

}

pragma GCC warning message

This is just like ‘pragma GCC error’ except that a warning message is issued instead of an error message. Unless -Werror is in effect, in which case this pragma will generate an error as well.

转载于:https://www.cnblogs.com/Dennis-mi/articles/9316897.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

GCC 消除编译器的特定警告 的相关文章

随机推荐

  • Centos中Docker的基本操作、镜像创建、数据管理、私有仓库的建立、端口映射和容器互联

    文章目录 一 Docker概述1 1 Docker概述1 2 Docker的核心概念及安装方式 二 Docker的基本操作2 1 环境准备及优化2 2 镜像的基本操作2 3 容器的操作 三 Docker镜像3 1 Docker镜像的分层3
  • 自编码器AutoEncoder解决异常检测问题

    自编码器AutoEncoder解决异常检测问题 一 自编码器 xff08 Auto Encoder xff09 介绍1 AE算法的原理2 AE算法的作用3 AE算法的优缺点 二 自编码器AutoEncoder解决异常检测问题 xff08 手
  • Snipaste(简单好用的截图工具)下载和使用

    下载 下载地址 xff1a https www snipaste com 简单版就够用了 绿色软件 xff0c 直接安装就行 使用快捷键 F1截图 xff0c 可测量大小 xff0c 设置箭头 xff0c 书写文字等F3在桌面置顶显示点击图
  • 通过外部中断按键去控制蜂鸣器开关

    EXTI功能说明 xff1a 要产生中断 xff0c 必须先配置好并使能中断线 根据需要的边沿检测设置2个触发寄存器 xff0c 同时在中断屏蔽寄存器的相应位写 1 允许中断请求 当外部中断线上发生了期待的边沿时 xff0c 将产生一个中断
  • 信号量的使用

    信号量 英文名字 xff1a semaphore 这里的进程信号量会为下列的信号量打基础 Ucos系统的信号量c线程的信号量java进程和线程的信号量 信号量作用 当多个进程 线程进行共享操作时 xff0c 用于资源保护 xff0c 以防止
  • 海康威视摄像头对接SDK实时预览功能和抓拍功能,懒癌福利,可直接CV

    海康威视摄像头完成实时预览功能和抓拍功能 背景思路 流程开发步骤1 海康的SDK xff0c 只需要在项目启动的时候初始化一次就行 xff0c 所以我直接将初始化SDK和加载DLL库的代码丢到启动类中去了 xff1a 2 先讲实时预览功能
  • 一、什么是SLAM?

    书中定义 xff1a slam是指移动智能体从一个未知环境里未知地点出发 xff0c 在运动过程中通过自身传感器观测周围环境 xff0c 并根据环境定位自身位置 xff0c 再根据自身的位置进行增量式的地图构建 xff0c 从而达到同时定位
  • ROS 创建工作空间流程

    本文以移植代码为例说明 目标是把一款云台SDK中的ROS代码部分抠出来移植到自己创建的工作空间中 记录下大致的流程 目录 1 创建工作空间 2 编译工作空间 xff08 可选 xff09 3 设置环境变量 xff08 可选 xff09 4
  • 边缘计算系列之MEC介绍

    前言 上篇内容 xff0c 跟大家简单介绍了边缘计算发展现状和边缘计算的基本概念 今天 xff0c 我们来讲讲MEC 目录 一 MEC的基本概念 二 MEC和边缘计算的关系 三 MEC的价值和优势 四 运营商MEC白皮书 1 MEC的基本概
  • 元学习(meta learning) 最新进展综述论文,28页pdf

    关注上方 深度学习技术前沿 xff0c 选择 星标公众号 xff0c 资源干货 xff0c 第一时间送达 xff01 本文综述了元学习在图像分类 自然语言处理和机器人技术等领域的应用 与深度学习不同 xff0c 元学习使用较少的样本数据集
  • 王海峰、李飞飞、山世光、王井东、汪玉……众多AI华人学者入选2022 IEEE Fellow...

    来源 xff1a 机器之心 北京时间 11 月 24 日凌晨 xff0c IEEE 公布了 2022 年度新一届会士的入选完整名单 IEEE 全称是美国电子电气工程师学会 xff08 Institute of Electrical and
  • 博后年薪58万起,副教授35万起,出站享80万安家费或100万房补,西电杭州研究院...

    来源 博士后招聘平台 编辑 硕博就业圈 研究院简介 XDU HANGZHOU 西安电子科技大学杭州研究院是西安电子科技大学为深入贯彻落实党中央 国务院关于深化产教融合改革部署和教育部 国家发展改革委 财政部关于加快新时代研究生教育改革发展的
  • 为什么要使用事件委托,使用事件委托的好处

    事件委托在我们程序员应聘阶段好多人都会被面试官问及到 xff0c 那到底什么是事件委托呢 xff1f 其实啊 xff0c 事件委托是本应给子元素注册的事件 xff0c 注册在父元素身上 然后使用 e tage方法由父元素统一分配给每个触发了
  • C++类和对象——友元

    目录 xff08 1 xff09 xff0c 全局函数做友元 xff08 2 xff09 xff0c 类做友元 xff08 3 xff09 xff0c 成员函数做友元 类中的私有属性 xff0c 也想让类外特殊的函数或者类进行访问 xff0
  • ubuntu系统安装TVM(保姆级)

    下载tvm span class token function git span clone recursive https github com apache tvm tvm 建议开代理 下载完成后在主目录看到tvm文件夹 依赖工具安装
  • Linux防火墙——Firewalld防火墙规则(内含防火墙的配置方法、图形化工具、firewall-cmd命令 )

    文章目录 Firewalld防火墙的配置一 Firewalld防火墙的配置方法运行时配置永久配置 二 Firewall config图形工具配置运行时配置 永久配置重新加载防火墙关联网卡到指定区域修改默认区域连接状态 区域 选项卡 服务 选
  • 人生苦短,我用k8s--------------Pod概念与Pod网络通讯方式详解

    一 pod概念 Pod是kubernetes中你可以创建和部署的最小也是最简的单位 Pod代表着集群中运行的进程 Pod中封装着应用的容器 xff08 数量大于等于1 xff0c docker最常用 xff0c 也可使用其他的 xff09
  • 装饰器三种写法之带参数的装饰器

    装饰器是AOP编程思想 xff0c 给主体函数增加功能 xff0c 又不让代码入侵到主体函数中 xff0c 实现高内聚 xff0c 低耦合 如果装饰功能部分代码也需要参数的话 xff0c 可以在原来的两层函数外面再加一层 xff0c 专门用
  • 把Linux下外设的USB端口号映射到固定的名字

    目录 1 固定USB设备的端口号的原理 2 rules文件的编写方法 3 映射结果查看 1 固定USB设备的端口号的原理 近期调试了一款云台 xff0c 控制方面需要用到串口通信 xff0c 调试过程中发现了一个问题 xff0c 就是 Li
  • GCC 消除编译器的特定警告

    GCC allows the user to selectively enable or disable certain types of diagnostics and change the kind of the diagnostic