__attribute__((unused)):可能不会用到,消除编译警告
__attribute__ unused:可能不会用到,消除编译警告
One of the easiest attributes to use, this marks a variable as intentionally being possibly unused. Not only does this quiet the compiler from issuing an unused-variable warning, it tells the human the same thing: this is intentional.
Of course, it's a good idea to actually remove variables that you're not using, this is not always possible. A common case of the unused int argc parameter to main() is one, as are variables sometimes excluded by conditional compilation.
int main(int argc, char **argv)
{/* code that uses argv, but not argc */
}
$ gcc -W test.c
test.c:1: warning: unused parameter 'argc'
The __attribute__ is added just after the variable name, and though it can appear unwieldy, it's a style you can get used to:
int main(int argc __attribute__((unused)), char **argv)
{ ...
Additional uses shown, each with a comment showing the compiler warning it might have generated. Here we assume the code is being compiled without the DEBUG macro being defined, which excludes the actual use of mypid.
/* warning: 'someFunction' declared 'static' but never defined */
static int someFunction() __attribute__((unused));int main(int argc __attribute__((unused)), char **argv)
{
/* warning: unused variable 'mypid' */
int mypid __attribute__((unused)) = getpid();#ifdef DEBUGprintf("My PID = %d\n", mypid);
#endifreturn 0;
}
__attribute__((unused)):可能不会用到,消除编译警告相关推荐
- defined but not used [-Wunused-function] 使用 __attribute__((unused)) 告诉编译器忽略此告警
在C程序中,如果定义了一个静态函数或变量,而没有去使用,编译时会有一个警告: 'at_wait_send_finish' defined but not used [-Wunused-function ...
- C语言之避免编译警告:unused用法(七)
栗子:test.c #include <stdio.h>int main(){//通用方式int __attribute__((unused)) count = 10;//2.此两种不能在 ...
- Xcode消除编译器警告
Whenever,Xcode警告对于我们来说都相当重要,提醒我们可能存在的错误.但是有时候,我们知道一切都好,everything is in the palm of my hand,我们想要消除那些 ...
- Effective Java之消除受检警告(二十四)
前记:在我编程过程中,经常会看到代码下面有一条横线,但是自己并没有注意警告的具体内容,一来觉得自己写的程序没有问题,二来,感觉改会很麻烦,这是不好的习惯,如果有这种编程习惯的,都要改正一下啊- 1.在 ...
- 强制消除Xcode警告的方法
比如我已经知道某行会报警告了,但是代码有这么写的道理,实在不想看到警告,可以用下面这个宏把这几行代码包住,就可以消除警告了. #pragma clang diagnostic push #pragma ...
- 【VS消除警告】VS消除特定警告/安全函数警告C4996 strncpy unsafe……
1.安全函数警告消除: 编译中出现 This function or variable may be unsafe. 消除方法: 1.在文件开头添加:#define _CRT_SECURE_NO_WA ...
- iOS OC消除黄色警告⚠️ (不断的更新中...)
开发一个项目时,难免会产生很多警告,一些是第三方或是老代码不再被支持造成的,但并不影响使用,这些警告其实可以直接隐藏掉!还有一些警告可能是系统方法弃用.不兼容指针类型.未使用变量.未使用default ...
- Xcode8 消除部分警告
1.注释中警告,设置为NO 2.unexpected file type 'wrapper.plug-in' in frameworks & libraries build phase 在Ge ...
- 如何消除SettingWithCopyWarning警告
虽然这不会影响运行中断,但看着就不是很美观,那我们应该如何避免这个警告呢? 问题分析: 出现该警告,主要是由于我直接取了rou_df0中的几列组成了一个新的dataframe,此时这个新的datafr ...
最新文章
- 20172319 实验二《树》实验报告
- Springmvc的handler method参数绑定常用的注解
- 从零入门 FreeRTOS 操作系统之任务的概念
- 【Java文件操作(五)】从txt文件中读取字符串、乱码原因
- 渗透测试:k8s的3种攻击手段(Kubernetes、未授权漏洞,端口:8080、6443、10250)
- LeetCode38.报数
- System.Collections深入探讨--如何创建自定义的集合类
- inno setup 打包脚本学习
- progressbar使用方法:进度画面大小,进度画面背景,进度百分比
- paip.重装系统需要备份的资料总结..
- 代码仓库-SVN分支策略
- 淘宝收货地址自动补全实现
- 二维码上可以用精密光纤激光打标机打吗?
- 经典游戏PK:魔兽争霸VS星际争霸VS红警
- 关于浏览器flash插件遇到的一些坑
- 【网易有数】BI数据分析工具一
- Mbps 和MB/s 之间的区别
- python中图片绘制和输出相关库的原理详解
- 前后端开发的心得体会_前后端对接的思考及总结
- 拉格朗日四平方和定理