The keyword format is either of the following:
__attribute__((attribute1, attribute2, ...))
__attribute__((__attribute1__, __attribute2__, ...))
For example:
void * Function_Attributes_malloc_0(int b) __attribute__((malloc));
static int b __attribute__((__unused__));
The following table summarizes the available function attributes.

Table 9-3 Function attributes that the compiler supports, and their equivalents

Function attribute Non-attribute equivalent
__attribute__((alias)) -
__attribute__((always_inline)) __forceinline
__attribute__((const)) __pure
__attribute__((constructor[(priority)])) -
__attribute__((deprecated)) -
__attribute__((destructor[(priority)])) -
__attribute__((format_arg(string-index))) -
__attribute__((malloc)) -
__attribute__((noinline)) __declspec(noinline)
__attribute__((no_instrument_function)) -
__attribute__((nomerge)) -
__attribute__((nonnull)) -
__attribute__((noreturn)) __declspec(noreturn))
__attribute__((notailcall)) -
__attribute__((pcs("calling_convention"))) -
__attribute__((pure)) -
__attribute__((section("name"))) -
__attribute__((unused)) -
__attribute__((used)) -
__attribute__((visibility("visibility_type"))) -
__attribute__((weak)) __weak
__attribute__((weakref("target"))) -

Usage

You can set these function attributes in the declaration, the definition, or both. For example:
void AddGlobals(void) __attribute__((always_inline));
__attribute__((always_inline)) void AddGlobals(void) {...}
When function attributes conflict, the compiler uses the safer or stronger one. For example, __attribute__((used)) is safer than __attribute__((unused)), and __attribute__((noinline)) is safer than __attribute__((always_inline)).
 
 

1. __attribute__((alias))

Examples

 不能在块范围内指定别名。编译器忽略附加到本地函数定义的属性,并将函数定义视为正常的本地定义。在输出对象文件中,编译器将别名调用替换为对原始函数名的调用,并在原始名称旁边发出别名。
如果原始函数被定义为静态函数,而别名被定义为extern,则编译器将原始函数更改为外部函数。

#include <stdio.h>
void foo(void)
{
printf("%s\n", __FUNCTION__);
}
void bar(void) __attribute__((alias("foo")));
void gazonk(void)
{
bar(); // calls foo
}

2. __attribute__((always_inline))

此函数属性指示函数必须内联。无论函数的特征如何,编译器都会尝试内联该函数。但是,如果这样做会导致问题,编译器不会内联函数。例如,递归函数只内联一次。

这个函数属性是ARM编译器支持的GNU编译器扩展。它具有相当__forceinline关键字。

 Examples

static int max(int x, int y) __attribute__((always_inline));
static int max(int x, int y)
{
return x > y ? x : y; // always inline if possible
}

3. __attribute__((const))

许多函数只检查传递给它们的参数,除了返回值没有作用。这是一个比__attribute__((pure))更严格的等级,因为允许读取全局内存是不是一个函数。如果已知函数只对其参数进行操作,则它可能受到常见的子表达式消除和循环优化的影响。

此函数属性是ARM编译器支持的GNU编译器扩展。它的关键字等效_pure

int Function_Attributes_const_0(int b) __attribute__((const));
int Function_Attributes_const_0(int b)
{
int aLocal=;
aLocal += Function_Attributes_const_0(b);
aLocal += Function_Attributes_const_0(b);
return aLocal;
}

在此代码中,可能只调用一次函数_properties_const_0,结果加倍以获得正确的返回值。

4.

最新文章

  1. Python标准模块--functools
  2. Standard Error of Mean(s.e.m.)
  3. Jenkins启动时报错:java.net.BindException: Address already in use: bind 解决方法
  4. S1 : 递归
  5. (转)jQuery Validation Plugin客户端表单证验插件
  6. 《Java并发编程实战》第十四章 构建自己定义的同步工具 读书笔记
  7. Java栈与堆 (转)
  8. Java知识体系纲要
  9. Coroutine协同程序介绍(Unity3D开发之三)
  10. scala的多种集合的使用(4)之列表List(ListBuffer)的操作
  11. 网址导航19A
  12. VS Code 调试 Angular 和 TypeScript 的配置
  13. 部署 HTTPS 访问 ( https:// )
  14. html-选择对象
  15. node.js监听文件变化
  16. PyQt5---firstwindow
  17. Java Date 日期 时间 相关方法
  18. 内建DNS服务器--BIND
  19. 配置React Native环境及解决运行异常
  20. HTTP报文01

热门文章

  1. Core Dump总结
  2. springboot接口:CommandLineRunner
  3. 5、通过Appium Desktop实现页面元素定位
  4. HTML —— 表格
  5. 33-Ubuntu-用户权限-04-修改目录权限
  6. hdu6341 /// 模拟 DFS+剪枝
  7. 随笔-ansible-6
  8. mongo之$max
  9. 《代码大全2》读书笔记 Week4
  10. JS对象 数组排序sort() sort()方法使数组中的元素按照一定的顺序排列。 语法: arrayObject.sort(方法函数)