牵着老婆满街逛

严以律己,宽以待人. 三思而后行.
GMail/GTalk: yanglinbo#google.com;
MSN/Email: tx7do#yahoo.com.cn;
QQ: 3 0 3 3 9 6 9 2 0 .

ffmpeg 中的GNU语法

转载自:http://blog.chinaunix.net/uid-21564437-id-3034917.html

    阅读ffmpeg源码是 发现一些函数前面加了 attribute_deprecated 属性;如:attribute_deprecated int url_fopen( AVIOContext **s, const char *url, int flags);
在libavutil/attributes.h  中有如下定义:

#ifndef attribute_deprecated
#if AV_GCC_VERSION_AT_LEAST(3,1)
#    define attribute_deprecated __attribute__((deprecated))
#else
#    define attribute_deprecated
#endif
#endif

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

在开发一些库的时候,API的接口可能会过时,为了提醒开发者这个函数已经过时。只要函数被使用,在编译是都会产生警告,警告信息中包含过时接口的名称及代码中的引用位置。
下面是GNU 网站(http://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Function-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/index.jsp?topic=/com.arm.doc.dui0348bc/Caccahah.html 有这些特性的详细介绍。

posted on 2013-01-29 16:05 杨粼波 阅读(777) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理