__attribute__变量属性

attribute((at(address))) variable attribute

语法
attribute((at(address)))
Where:
address
is the desired address of the variable.

Usage
The variable is placed in its own section, and the section containing the variable is given an appropriate type by the compiler:
1.Read-only variables are placed in a section of type RO.
2.Initialized read-write variables are placed in a section of type RW.
Variables explicitly initialized to zero are placed in:
1).A section of type ZI in RVCT 4.0 and later.
2).A section of type RW (not ZI) in RVCT 3.1 and earlier. Such variables are not candidates for the ZI-to-RW optimization of the compiler.
3.Uninitialized variables are placed in a section of type ZI.

限制
The linker is not always able to place sections produced by the at variable attribute.
The compiler faults use of the at attribute when it is used on declarations with incomplete types.
Note
GNU 编辑器不支持这种变量属性

Example

const int x1 __attribute__((at(0x10000))) = 10; /* RO */
int x2 __attribute__((at(0x12000))) = 10; /* RW */
int x3 __attribute__((at(0x14000))) = 0; /* RVCT 3.1 and earlier: RW.
                                          * RVCT 4.0 and later: ZI. */
int x4 __attribute__((at(0x16000))); /* ZI */
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
__attribute__ 是GCC编译器提供的一种扩展语法,用于对变量、函数、结构体等进行属性设置。它可以用来指定变量的特殊属性,如对齐方式、可见性、优化等。下面是__attribute__ 变量使用方法的介绍: 1. 对齐属性(alignment attribute):可以使用__attribute__((aligned(n)))来指定变量的对齐方式,其中n表示对齐的字节数。例如,__attribute__((aligned(4)))可以将变量对齐到4字节边界。 2. 可见性属性(visibility attribute):可以使用__attribute__((visibility("visibility_type")))来指定变量的可见性,其中visibility_type可以是"default"、"hidden"或"protected"。默认情况下,变量的可见性是"default",可以被外部文件访问。 3. 强制内联属性(force inline attribute):可以使用__attribute__((always_inline))来强制将函数或变量内联展开,即使编译器认为不需要内联展开。 4. 优化属性(optimize attribute):可以使用__attribute__((optimize("optimization_level")))来指定变量的优化级别,其中optimization_level可以是"0"、"1"、"2"、"3"或"s"。默认情况下,优化级别是"0",表示不进行优化。 5. 其他属性:除了上述常用的属性外,__attribute__ 还支持其他一些属性,如deprecated(标记为过时)、used(标记为被使用)、unused(标记为未使用)等。 需要注意的是,__attribute__ 是GCC编译器的扩展语法,不同的编译器可能支持不同的属性。在使用__attribute__ 时,应该查阅相关编译器文档以确保属性的正确使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值