原文网址:http://blog.csdn.net/lizzywu/article/details/9419145

各个层次的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.

          #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.

          #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’.

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

example:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-label"
....

#pragma GCC diagnostic pop

【转】各个层次的gcc警告 #pragma GCC diagnostic ignored "-Wunused-parameter" --不错的更多相关文章

  1. 编译器处理警告、错误 #pragma GCC diagnostic ignored "-Wunused"

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

  2. 各个层次的gcc警告

    http://blog.csdn.net/lizzywu/article/details/9419145 各个层次的gcc警告从上到下覆盖 变量(代码)级:指定某个变量警告 int a __attri ...

  3. msvc/gcc:中用#pragma指令关闭特定警告(warning)

    在使用一些第三方库或源码的时候,经常会遇到编译时产生warnings情况,这些warning不是我们自己的代码产生的,当然也不好去修改,但每次编译都显示一大堆与自己代码无关的警告也着实看着不爽,更麻烦 ...

  4. GCC(警告.优化以及调试选项)

    GCC(警告.优化以及调试选项) [介绍] gcc and g++分别是gnu的c & c++编译器   gcc/g++在执行编译工作的时候,总共需要4步   1.预处理,生成.i的文件 预处 ...

  5. #pragma GCC system_header用法

    在看公司公共库的头文件中发现了:#pragma GCC system_header一行,以前没有见过这种用法,在网上查了一下,解释如下: 从#pragma GCC system_header直到文件结 ...

  6. GCC 警告提示的用法

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

  7. fedora/centos下gcc编译出现gcc: error trying to exec ‘cc1plus’: execvp: No such file or directory

    fedora/centos下gcc编译出现gcc: error trying to exec 'cc1plus': execvp: No such file or directory解决办法 翻译自: ...

  8. gcc警告: warning: dereferencing type-punned pointer will break strict-aliasing rules

    Q: 在高优化级别下,不同类型指针之间的强制类型转换可能会触发以下警告: warning: dereferencing type-punned pointer will break strict-al ...

  9. GCC警告选项例解

    程序员是追求完美的一族,即使是一般的程序员大多也都不想看到自己的程序中有甚至那么一点点的瑕疵.遇到任意一条编译器警告都坚决不放过.有人会说:我们可以使用比编译器更加严格的静态代码检查工具,如splin ...

随机推荐

  1. redis 学习笔记一

    找了半天,发觉还是redis的源码看起来比较舒服.所以决定今年把redis的源码读一遍顺便做个读书笔记.好好记录下.话说现在越来不越不愿意用脑袋来记录东西,喜欢靠note来记.话说这样不爱用脑会不会过 ...

  2. scp 对拷文件夹 和 文件夹下的所有文件 对拷文件并重命名

    对拷文件夹 (包括文件夹本身) scp -r   /home/wwwroot/www/charts/util root@192.168.1.65:/home/wwwroot/limesurvey_ba ...

  3. Hive 6、Hive DML(Data Manipulation Language)

    DML主要是对Hive 表中的数据进行操作的(增 删 改),但是由于Hadoop的特性,所以单条的修改.删除,其性能会非常的低所以不支持进行级操作: 主要说明一下最常用的批量插入数据较为常用的方法: ...

  4. Bootstrap--本地安装使用

    1.到官网下载:http://v2.bootcss.com 2.下载后是一个压缩文件,把它放在相应的工作目录下,然后解压. 3.新建一个测试文件,然后导入两个文件.

  5. 压位加速-poj-2443-Set Operation

    题目链接: http://poj.org/problem?id=2443 题目意思: 有n个集合(n<=1000),每个集合有m个数ai(m<=10000,1=<ai<=100 ...

  6. [Javascript] Task queue & Event loop.

    Javascript with Chorme v8 engine works like this : For Chorme engine, v8, it has call stack. And all ...

  7. Hacker(20)----手动修复Windows系统漏洞

    Win7系统中存在漏洞时,用户需要采用各种办法来修复系统中存在的漏洞,既可以使用Windows Update修复,也可使用360安全卫士来修复. 一.使用Windows Update修复系统漏洞 Wi ...

  8. RAC 的一些概念性和原理性的知识(转)

    一 集群环境下的一些特殊问题 1.1 并发控制 在集群环境中, 关键数据通常是共享存放的,比如放在共享磁盘上. 而各个节点的对数据有相同的访问权限, 这时就必须有某种机制能够控制节点对数据的访问. O ...

  9. MySQL复制协议

    http://hamilton.duapp.com/detail?articleId=27

  10. [.NET | 發佈] 如何指定固定的目錄給程式調用的外部DLL?

    1.OverView 一般程式只會查找與主程式同目錄的DLL檔案 解決方案主要可以參考這篇:http://support.microsoft.com/kb/837908 2.實作app.config方 ...