各个层次的gcc警告
来源:互联网 发布:土行孙网络加速器 编辑:程序博客网 时间:2024/05/17 02:07
从上到下覆盖
变量(代码)级:指定某个变量警告
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 eachpop
. If apop
has no matchingpush
, 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 pop foo(c); /* error is given for this one */ #pragma GCC diagnostic pop foo(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’.
- 各个层次的gcc警告
- 各个层次的gcc警告
- iOS学习笔记76-各个层次的gcc警告
- android各个层次的理解
- 项目各个层次的作用
- GCC 警告提示的用法
- TCP IP协议栈的各个层次
- 浅谈OSI模型的各个层次
- gcc警告
- gcc警告
- gcc警告
- GCC警告
- 有效利用GCC的警告信息
- gcc 常见的编译错误,警告总结
- GCC编译警告选项的学习
- GCC编译时的警告说明
- gcc编译各个阶段以及各个阶段的作用
- J2EE (Struts+hibernate)中各个层次的对象转换
- 【NO.3】 c program to caculate and display sum of two matrix
- 机器学习中的算法-支持向量机(SVM)基础
- [中文翻译]<The Swift Programming Language> - About Swift 关于Swift
- I/O非阻塞函数实践:poll
- 转身,情义淡然
- 各个层次的gcc警告
- To avoid email sending by programming to go into spam folder让发送的邮件到收件箱而不是垃圾邮件
- 浅谈苹果新开发语言:Swift
- 中国的 Android:尚未发掘的应用市场?
- 研大考研:暑期集训优势
- 视图
- 黑马程序员--银行业务调度系统
- ios下获取系统所有进程PID信息
- 浅谈HOOK API 都是一些很老很基础的东西