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

各个层次的gcc警告的更多相关文章

  1. 【转】各个层次的gcc警告 #pragma GCC diagnostic ignored "-Wunused-parameter" --不错

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

  2. GCC 警告提示的用法

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

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

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

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

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

  5. GCC警告选项例解

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

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

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

  7. GCC 警告

    -w -W禁止/开启 编译警告的打印.这个警告不建议使用.大约2012年底,公司代码进行一次大重构,另外从Codeblock集成开发环境转向Makefile管理,Makefile里面默认使用了-w,因 ...

  8. GCC警告提示错误“cc1:all warnings being treated as errors”

    http://blog.csdn.net/zhangjs0322/article/details/25131787

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

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

随机推荐

  1. RichTextBox指定全部文字显示不同颜色及部分文字高亮颜色显示

    指定全部显示不同颜色: public void SetTextContent(string text, ColorEnum color) { Font font = , FontStyle.Bold) ...

  2. Java 小数类 及四舍五入的方法 精度非常高的小数时用

    注意假设结果是无限位小数,不指定位数进行四舍五入的话会报错 import java.util.Scanner; import java.math.BigDecimal; public class Ma ...

  3. 第一个Verilog程序:通用加法器

    Verilog作为一门硬件描述语言,快速掌握它的方法就是不断的练习,反复动手实践,通过例子掌握隐藏在语句背后的硬件电路.下面是第一个需要学习的Verilog例子: )( :] a, :] b, inp ...

  4. cocos2d-x开发记录:二,基本概念(粒子系统,Scheduler和定时器)

    七,粒子系统 1.导言 术语粒子系统是指计算机图形学技术,它使用大量非常小的精灵或其他图形对象来模拟某些种类的“模糊”现象,于传统渲染技术相比,它很难复制.通常是高度混沌无序的系统,自然现象.化学反应 ...

  5. C#特性Attribute学习

    起初一直纠结于如何调用特性附着在下面那个成员的值,后来发现不需要调用,通过反射加载的时候是自动绑定上去的,即 获得成员对象之后,有一个方法可以获得特性标签. 其实从类库提供者,和类库使用者的角度,分开 ...

  6. Photoshop制作Android UI: 怎样将图片背景变为透明

    看烦了代码.今天玩玩PS吧.本人是PS小白.Android开发中不可避免的要做一些图片,但我发现居然没有相似的专门教程.真想拜个美工为师.还记得2012年去宁波实习时为了将图片缩小我还matlab写个 ...

  7. iOS之Sqlite3封装

    一.代码下载 代码下载地址 二.实例效果展示 imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="效果图二.png&q ...

  8. 【快速查阅】SQLPLUS连接ORACLE

    使用SQLPLUS连接ORACLE常用的有两种方式. 一.简易方式 sqlplus 用户名/密码@IP或主机名:端口/数据库服务名称 二.预先配置TNSNAMES的方式 在“%ORACLE_HOME% ...

  9. 解决NSImage绘制的时候图像模糊

    Mac下NSImage绘制模糊的原因之一是draw到了非整数像素上,框架在渲染的时候就会模糊. 针对这一原因写了以下工具: /** * @brief 一劳永逸的解决NSImage绘制的时候绘到浮点值像 ...

  10. div,contenteditable编辑器之ctrl+enter换行,enter发送

    //回车发消息 $scope.keyDownSend = function ($event) { var keycode = window.event?$event.keyCode:$event.wh ...