用__attribute__((deprecated))管理过时的代码
来源:互联网 发布:python进入命令行模式 编辑:程序博客网 时间:2024/06/07 01:19
在开发一些库的时候,API的接口可能会过时,为了提醒开发者这个函数已经过时。可以在函数声明时加上attribute((deprecated))属性,如此,只要函数被使用,在编译是都会产生警告,警告信息中包含过时接口的名称及代码中的引用位置。
attribute可以设置函数属性(Function Attribute)、变量属性(Variable Attribute)和类型属性(Type Attribute)。
attribute语法格式为:attribute ((attribute))
注意: 使用attribute的时候,只能函数的声明处使用attribute,
#include <stdio.h>#include <stdlib.h>#ifdef __GNUC__# define GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > (x) || __GNUC__ == (x) && __GNUC_MINOR__ >= (y))#else# define GCC_VERSION_AT_LEAST(x,y) 0#endif#if GCC_VERSION_AT_LEAST(3,1)# define attribute_deprecated __attribute__((deprecated))#elif defined(_MSC_VER)# define attribute_deprecated __declspec(deprecated)#else# define attribute_deprecated#endif/* Variable Attribute */attribute_deprecated int variable_old = 0;/* Function Attribute */attribute_deprecated void function_old(void);void function_old(void){ printf("old function.\n"); return;}int main(void){ variable_old++; function_old(); return EXIT_SUCCESS;}
在编译时会出现类似警告:
# gcc attribute_deprecated.c -o test
attribute_deprecated.c: In function ‘main’:
attribute_deprecated.c:33: warning: ‘variable_old’ is deprecated (declared at attribute_deprecated.c:20)
attribute_deprecated.c:35: warning: ‘function_old’ is deprecated (declared at attribute_deprecated.c:25)
0 0
- 用__attribute__((deprecated))管理过时的代码
- C++库研究笔记--用__attribute__((deprecated)) 管理过时代码
- Android一些过时的(Deprecated)方法取代
- 阅读《第一行代码》,接收短信实验时,SmsMessage类deprecated过时的原因和解决方法
- iOS废弃的API:NS_AVAILABEL_IOS and NS_DEPRECATED_IOS and __attribute__((deprecated))
- 关于Hibernate5.2之后createCriteria(),@deprecated(过时的)
- Android TabHost TabActivity Deprecated 过时
- 'setBackgroundDrawable()' is deprecated,setBackgroundDrawable过时
- 'getColor(int)' is deprecated ,getColor过时
- 'getDrawable(int)' is deprecated,getDrawable过时
- FilterDispatcher已被标注为过时解决办法 >>> FilterDispatcher <<< is deprecated!
- FilterDispatcher已被标注为过时解决办法 >>> FilterDispatcher <<< is deprecated!
- struts2 控制台警告信息 FilterDispatcher <<< is deprecated! 提示 FilterDispatcher 过时
- FilterDispatcher已被标注为过时解决办法 >>> FilterDispatcher <<< is deprecated!
- FilterDispatcher已被标注为过时解决办法 >>> FilterDispatcher <<< is deprecated!
- FilterDispatcher已被标注为过时解决办法 >>> FilterDispatcher <<< is deprecated!
- FilterDispatcher已被标注为过时解决办法 >>> FilterDispatcher <<< is deprecated!
- FilterDispatcher已被标注为过时解决办法 >>> FilterDispatcher <<< is deprecated!
- 51Nod-1280-前缀后缀集合
- 711D
- 实现memove
- FreeWAF开源的WEB应用防火墙免邀请码下载
- 苹果app上传AppStore因为IPv6被拒绝,本地搭建IPv6测试环境
- 用__attribute__((deprecated))管理过时的代码
- 20160830MYSQL的密码更改基本操作
- post和get传值
- 手机充电器原理
- linux的cpu资源调优方法
- 完全背包
- 【Codeforces Round #369 (Div. 2)】Codeforces 711B Chris and Magic Square
- java中File类的使用方法
- libxml2库 读取xml文件,写xml文件