请选择 进入手机版 | 继续访问电脑版

ChinaFFmpeg

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 7691|回复: 4

[源码] 关于attribute_deprecated这个编译定义有高手能讨论指点下吗

[复制链接]
发表于 2013-10-26 15:53:39 | 显示全部楼层 |阅读模式
在libavutil库里面充满了关于attribute_deprecated这个编译器定义,因为比较高端且出现频率较高,所以希望哪位高手重点讲解讨论下。
谢谢了!~


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

发表于 2013-10-27 10:11:03 | 显示全部楼层
阅读ffmpeg源码是 发现一些函数前面加了 attribute_deprecated 属性;如:attribute_deprecated int url_fopen( AVIOContext **s, const char *url, int flags);
在libavutil/attributes.h  中有如下定义:
   83 #ifndef attribute_deprecated
   84 #if AV_GCC_VERSION_AT_LEAST(3,1)
   85 #    define attribute_deprecated __attribute__((deprecated))
   86 #else
   87 #    define attribute_deprecated
   88 #endif
   89 #endif

__attribute__ 语法为GNU C 的特性,__attribute__可以设置函数属性(Function Attribute)、变量属性(Variable Attribute)和类型属性(Type Attribute)。
__attribute__语法格式为:__attribute__ ((attribute))
需要注意的是: 使用__attribute__的时候,只能函数的声明处使用__attribute__,并且在“;“前。

在开发一些库的时候,API的接口可能会过时,为了提醒开发者这个函数已经过时。只要函数被使用,在编译是都会产生警告,警告信息中包含过时接口的名称及代码中的引用位置。
下面是GNU 网站(http://gcc.gnu.org/onlinedocs/gc ... ion-Attributes.html)上对这个属性的解释:
deprecated
The deprecated attribute results in a warning if the function is used anywhere in the source file. This is useful when identifying functions that are expected to be removed in a future version of a program. The warning also includes the location of the declaration of the deprecated function, to enable users to easily find further information about why the function is deprecated, or what they should do instead. Note that the warnings only occurs for uses:
          int old_fn () __attribute__ ((deprecated));
          int old_fn ();
          int (*fn_ptr)() = old_fn;
     
results in a warning on line 3 but not line 2.
下面是一个列子:
root@wang:/work/wanghuan/gnu# cat gnu.c
#include <stdlib.h>
#include <stdio.h>

__attribute__((deprecated)) void attribute();
void attribute()
{
        printf("GNU attribute \n");
}

int main()
{
        attribute();
        return 0;
}
root@wang:/work/wanghuan/gnu# gcc gnu.c -o gnu
gnu.c: In function ‘main’:
gnu.c:12: warning: ‘attribute’ is deprecated (declared at gnu.c:5)     //编译警告
root@wang:/work/wanghuan/gnu# ./gnu
GNU attribute

关于__attribute__属性,有多种类型,由于ARM编译器支持GNU语法,在ARM的网站http://infocenter.arm.com/help/i ... 348bc/Caccahah.html 有这些特性的详细介绍。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-10-27 11:05:55 | 显示全部楼层
这个我也看了,有没有更加详细的资料呢
回复 支持 反对

使用道具 举报

发表于 2013-10-27 11:07:58 | 显示全部楼层
pqiankui 发表于 2013-10-27 11:05
这个我也看了,有没有更加详细的资料呢

你要干啥?如果那个gcc的连接都不能解决你的问题;
那么这个能否忽略不计,就当他是个不存在的东西就行了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-10-27 11:08:36 | 显示全部楼层
T-Bagwell 发表于 2013-10-27 11:07
你要干啥?
这个能否忽略不计,就当他是个不存在的东西就行了

好吧,在编译上用gcc没有任何差别是吧
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|Archiver|ChinaFFmpeg

GMT+8, 2024-4-17 02:16 , Processed in 0.049657 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表