各个层次的gcc警告
从上到下覆盖

变量(代码)级:指定某个变量警告

int a __attribute__ ((unused));
指定该变量为"未使用的".即使这个变量没有被使用,编译时也会忽略则个警告输出.

文件级:在源代码文件中诊断(忽略/警告)

语法:

#pragma GCC diagnostic [error|warning|ignored] "-W<警告选项>"

诊断-忽略:(关闭警告)
#pragma  GCC diagnostic ignored  "-Wunused"

#pragma  GCC diagnostic ignored  "-Wunused-parameter"

诊断-警告:(开启警告)
#pragma  GCC diagnostic warning  "-Wunused"

#pragma  GCC diagnostic warning  "-Wunused-parameter"

诊断-错误:(开启警告-升级为错误)
#pragma  GCC diagnostic error  "-Wunused"

#pragma  GCC diagnostic error  "-Wunused-parameter"

用法:

在文件开头处关闭警告,在文件结尾出再开启警告,这样可以忽略该文件中的指定警告.

项目级:命令行/编译参数指定

警告:
gcc main.c -Wall 忽略:
gcc mian.c -Wall -Wno-unused-parameter //开去all警告,但是忽略 -unused-parameter警告

选项格式: -W[no-]<警告选项>
如 : -Wno-unused-parameter # no- 表示诊断时忽略这个警告

来源:https://github.com/zodiac1111/note/blob/master/note/gcc/gcc-ignored-warning.markdown#%E6%96%87%E4%BB%B6%E7%BA%A7%E5%9C%A8%E6%BA%90%E4%BB%A3%E7%A0%81%E6%96%87%E4%BB%B6%E4%B8%AD%E8%AF%8A%E6%96%AD%E5%BF%BD%E7%95%A5%E8%AD%A6%E5%91%8A


6.59.10 Diagnostic Pragmas

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.

<span style="font-size:18px;">          #pragma GCC diagnostic warning "-Wformat"#pragma GCC diagnostic error "-Wformat"#pragma GCC diagnostic ignored "-Wformat"
</span>

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.

<span style="font-size:18px;">          #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 popfoo(c);                       /* error is given for this one */#pragma GCC diagnostic popfoo(d);                       /* depends on command-line options */
</span>

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.

<span style="font-size:18px;">          #pragma message "Compiling " __FILE__ "..."
</span>

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

<span style="font-size:18px;">          #define DO_PRAGMA(x) _Pragma (#x)#define TODO(x) DO_PRAGMA(message ("TODO - " #x))TODO(Remember to fix this)
</span>

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

来源:http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html

各个层次的gcc警告相关推荐

  1. 【GCC】gcc警告选项汇总--编辑中|gcc编译选项

    目录 前言 请求或取消警告选项 GCC编译选项 参考原文:https://blog.csdn.net/qq_17308321/article/details/79979514 前言 警告:不是错误的, ...

  2. linux gcc忽略警告,GCC 警告提示的用法

    本节主要讲解GCC的警告提示功能.GCC包含完整的出错检查和警告提示功能,它们可以帮助Linux程序员写出更加专业和优美的代码.我们千万不能小瞧这些警告信息,在很多情况下,含有警告信息的代码往往会有意 ...

  3. gcc警告选项汇总 转

    ---------------- 原文链接:https://blog.csdn.net/qq_17308321/article/details/79979514 参考资料:https://gcc.gn ...

  4. GCC 警告选项 -Werror

    cc1plus: all warnings being treated as errors 解决办法:只需要找到相应的Makefile,去掉编译选项中的 -Werror 即可. --Werror 视警 ...

  5. 【转】GCC警告选项例解 -- 不错

    原文网址:http://blog.csdn.net/hcx25909/article/details/7383716 程序员是追求完美的一族,即使是一般的程序员大多也都不想看到自己的程序中有甚至那么一 ...

  6. c语言_std=c11,关于带有std = c11 arg的c:GCC警告

    这是使用pthread_kill()调用的一些C源代码: #include #include #include int main(int argc, char *argv[]) { pthread_t ...

  7. gcc:警告:argument 1 value ‘18446744073709551615’ exceeds maximum object size 9223372036854775807

    警告 ]oot@rhel-cleanmodules:~/mzhan017/test[root@rhel-cleanmodules test]# gcc memory.c memory.c: In fu ...

  8. linux c 编译器处理警告、错误 #pragma GCC diagnostic ignored -Wunused

    各个层次的gcc警告 从上到下覆盖 变量(代码)级:指定某个变量警告 int a __attribute__ ((unused)); 指定该变量为"未使用的".即使这个变量没有被使 ...

  9. 【CentOS Linux 7】【gcc编译器】

    Linux系统及应用---调研报告 [CentOS Linux 7]实验1[VMware安装.新建虚拟机:63个基础命令运行结果图] [CentOS Linux 7]实验2[Shell编程及应用] [ ...

最新文章

  1. Android 依赖库发布(上传 Library 到 JCenter)gradle最高支持4.4
  2. 静态方法多次调用内存_java虚拟机的内存分析
  3. 华为鸿蒙系统可以用在哪里,【图片】华为鸿蒙系统的厉害之处在于 你可能非用不可 !【手机吧】_百度贴吧...
  4. 关于DJANGO MODELS的个人理解和RELATED_NAME的使用
  5. 米筐量化不支持c语言_从零开始学量化(三):数据获取途径
  6. 95-090-022-源码-bin脚本-CLI提交Job的时候加载插件
  7. Flink 尚硅谷学习笔记
  8. 四参数拟合曲线_Origin进行体外释药规律的拟合
  9. 西门子g120变频器接线图_西门子变频器G120如何通过速度限幅来避免飞车的发生...
  10. 用html给图片加像素,更改照片像素和大小
  11. Qt 网络聊天室项目
  12. 6 errors and 0 warnings potentially fixable with the `--fix` option.
  13. 网站搭建需要多少钱?如何搭建比较省钱呢?
  14. 新晋云计算工程师就业的感受和经验分享
  15. 开关电源MOS管如何选择,参数是核心
  16. 【读书笔记】《学会提问》——受用一生的批判性思维
  17. Python的GUI编程(三)Entry(条目)
  18. 图像拼接(十一):双摄像头实时拼接+stitching_detailed
  19. vue 相关的面试题
  20. Attention-based Extraction of Structured Information from Street View Imagery:基于注意力的街景图像提取结构化信息

热门文章

  1. js 页面所有超链接后加随机数 基于jquery
  2. VNC源码研究(一)
  3. docker 查询或获取私有仓库(registry)中的镜像
  4. 【旧文章搬运】无Device的驱动如何通信
  5. 集腋成裘-10-ECharts -未知-03
  6. ubuntu下sogou突然不能用
  7. link2001错误无法解析外部符号metaObject
  8. win8开发中需要用到一些系统版本之类的统计信息,总结如下。
  9. 博客诞生过程与变革:十年来谁是写博客第一人?
  10. Breadth-first Search(广度优先搜索)专题2