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.

function attributes, MDK的更多相关文章

  1. Uboot命令U_BOOT_CMD分析

    其中U_BOOT_CMD命令格式如下: U_BOOT_CMD(name,maxargs,repeatable,command,"usage","help") 各 ...

  2. Backbone源码分析(二)

    在传统MVC框架模式中,Model承担业务逻辑的任务.Backbone作为一个mvc框架,主要的业务逻辑交由Model与Collection来实现.Model代表领域对象,今天主要学一下Model源码 ...

  3. RequireJS与Backbone简单整合

    前言 昨天我们一起学习了Backbone,最后做了一个备忘录的例子,说是做了不如说是看了下官方提供的例子,所以最终我感觉我们还是没能掌握Backbone,今天还得做个其它例子先. 然后前面也只是草草学 ...

  4. 前端MVC框架Backbone 1.1.0源码分析(二) - 模型

    模型是什么? Models are the heart of any JavaScript application, containing the interactive data as well a ...

  5. 用backbone实现的一个MVC的小demo

    一.Apache配置 本实例需要使用php支持.要现在Apache中配置虚拟目录,在Apache下的httpd-vhosts.conf文件中添加如下代码 <VirtualHost *:80> ...

  6. Backbone源码阅读手记

    Backbone.js是前端的MVC框架,它通过提供模型Models.集合Collection.视图Veiew赋予了Web应用程序分层结构.从源码中可以知道,Backbone主要分了以下几个模块: ( ...

  7. __attribute__

    转来的: http://www.cnblogs.com/astwish/p/3460618.html __attribute__ 你知多少? GNU C 的一大特色就是__attribute__ 机制 ...

  8. Programming Entity Framework 翻译(1)-目录

    1. Introducing the ADO.NET Entity Framework ado.net entity framework 介绍 1 The Entity Relationship Mo ...

  9. 【转】Backbone使用总结

    转自  http://www.pchou.info/javascript/2014/06/26/backbone-summary-01.html 开始在项目中大规模使用backbone,一路磕磕碰碰, ...

随机推荐

  1. PHP ftp_alloc() 函数

    定义和用法 ftp_alloc() 函数为要上传到 FTP 服务器的文件分配空间. 如果成功,该函数返回 TRUE.如果失败,则返回 FALSE. 语法 ftp_alloc(ftp_connectio ...

  2. 【Flutter学习】基本组件之基本列表ListView组件

    一,概述 列表是前端最常见的需求. 在flutter中,用ListView来显示列表页,支持垂直和水平方向展示,通过一个属性我们就可以控制其方向,列别有以下分类 水平列表 垂直列表 数据量非常大的列表 ...

  3. MySql中创建用户,授权

    第一天搞MySql好多东西都不会,幸好有网络的强大资源,首先需要注意的是任何一条sql语句都是要以分号结尾的,不然很是蛋疼的 1.新建用户. //登录MYSQL @>mysql -u root  ...

  4. 排序+模拟+优先队列——cf1248E

    其实是个模拟题.. /* 每个人都有一个口渴时间,如果口渴时,其前面没有人在排队,那么其就去排队接水,反之一直等到前面没有人排队 问每个人接完水的时间 每个没轮到的人都在位置上等前面的人接完水,然后他 ...

  5. Hbase的rowkey设计

    HBase的rowKey设计技巧 1.设计宗旨与目标 主要目的就是针对特定的业务模型,按照rowKey进行预分区设计,使之后面加入的数据能够尽可能的分散于不同的rowKey中.比如复合RowKey. ...

  6. go语言中使用正则表达式

    一.代码 package main import ( "fmt" "regexp" ) func main() { text := `Hello 世界!123 ...

  7. firefox显示 您的连接不安全 解决办法

    在地址栏键入"about:config" 点击“我了解此风险” 在下方任意位置右键,选择新建布尔值 输入首选项名称为“security.enterprise_roots.enabl ...

  8. 微信小程序利用canvas生成海报分享图片

    一 . 效果 这是借用女神照生成的分享的海报,图片来自网络. 新增了poster组件和更新图片自适应 二 . 准备 准备两张图片连接,最好是自己开发账号验证的https图片链接. 三 . 实现思路 其 ...

  9. chromedriver安装(谷歌浏览器驱动安装)

    如果程序执行错误,浏览器没有打开,那么应该是没有装 Chrome 浏览器或者 Chrome 驱动没有配置在环境变量里.下载驱动,然后将驱动文件路径配置在环境变量即可. chromedriver下载地址 ...

  10. python 一些特殊用法和坑

    https://github.com/leisurelicht/wtfpython-cn