说明
官方文档说明如下:
This function attribute enables you to specify multiple aliases for a function.
Aliases must be defined in the same translation unit as the original function.
此函数属性使您可以为函数指定多个别名。
别名必须在与原始函数相同的翻译单元中定义。
1 | static struct config __internal_config; ///< 全局静态内部配置 |
示例
在输出对象文件中,编译器将别名调用替换为对原始函数名称的调用,并在原始名称旁边发出别名。 例如:
1 | static int oldname(int x, int y) { |
该代码编译为:
1 | AREA ||.text||, CODE, READONLY, ALIGN=2 |
如果原始函数定义为 static 但别名定义为 extern,则编译器将原始函数更改为外部函数。
该函数属性是ARM编译器支持的GNU编译器扩展。
变量名称也可以使用相应的变量属性来命名。
__attribute__((alias))
语法
1 | return-type newname([argument-list]) __attribute__((alias("oldname"))); |
- oldname 需要设置别名的函数名称。
- newname 是别名函数的新名称。
例子
1 |
|