【ARM 嵌入式 编译系列 11.3 -- GCC attribute packed noreturn constructor 介绍】
文章目录
GCC 的 __attribute__
是一个编译器扩展特性,允许开发者在源代码中设置函数属性(function attributes)、变量属性(variable attributes)和类型属性(type attributes)。这些属性可以影响函数、变量或类型的行为。
以下是一些常见的 __attribute__
属性:
__attribute__((constructor))
和 __attribute__((destructor))
:这两个属性可以用于函数,让函数在 main 函数执行前(对于 constructor)或执行后(对于 destructor)被自动执行。
例如:
__attribute__((constructor)) void before_main()