ffmpeg 中的GNU语法

简介:

阅读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

目录
相关文章
|
编译器 Linux 程序员
GNU C 扩展语法:关键字__attribute__ 使用
GNU C 扩展语法:关键字__attribute__ 使用
2207 0
|
存储 编解码 编译器
GNU C 扩展语法:零初始化数组
零长度数组、变长度数组都是 GNU C 编译器支持的数组类型。今天我们来回顾一下零长度数组。
591 0
|
存储 安全 编译器
GNU C 扩展语法:指定初始化与语句表达式
GNU C 扩展语法:指定初始化与语句表达式
951 0
|
编译器 Linux 开发工具
|
前端开发 C语言
gcc动态库升级
gcc动态库升级
1526 1
|
存储 编译器 C语言
深入理解GCC 和 G++ 编译器
GCC 和 G++ 是 GNU 工具链中的核心编译器,支持 C 和 C++ 程序开发。本文详细介绍其编译流程、常用选项及动态链接与静态链接的区别。编译过程分为预处理、编译、汇编和链接四个阶段,每个阶段有特定任务和命令选项。常用选项如 `-E`、`-S`、`-c` 和 `-o` 分别用于预处理、生成汇编代码、生成目标文件和指定输出文件。动态链接节省空间且易于更新,但依赖运行时库;静态链接独立高效,但文件较大且更新困难。合理选择优化选项(如 `-O0` 至 `-O3`)可提升程序性能。掌握这些知识有助于开发者更高效地编写、调试和优化代码。
深入理解GCC 和 G++ 编译器
|
编译器 Linux C语言
gcc的编译过程
GCC(GNU Compiler Collection)的编译过程主要包括四个阶段:预处理、编译、汇编和链接。预处理展开宏定义,编译将代码转换为汇编语言,汇编生成目标文件,链接将目标文件与库文件合并成可执行文件。
867 11
|
编译器 开发工具 C语言
Gcc 链接文件
Gcc 链接文件
620 4
|
C语言
gcc的简易用法
【5月更文挑战第10天】gcc的简易用法。
427 8