C 扩展关键字
来源:互联网 发布:涂师傅数据恢复raw 编辑:程序博客网 时间:2024/06/07 11:00
gcc 扩展关键字
__attribute__
- 设置函数属性, 变量属性, 数据类型属性等, 向编译器提供更多数据, 帮助编译器执行优化
描述函数属性
- 使用 addr2line 工具分析源代码, 统计程序的运行状态
void fun() __attribute__ ((regparm(0))); //不需要通过任何寄存器来传递参数, 参数只是通过堆栈来传递void fun() __attribute__ ((regparm(3))); //通过寄存器传递多达3个的参数(EAX, EDX, ECX), 更多的参数才通过堆栈传递, 减少一些入栈出栈操作, 调用更快void noreturnfun() __attribute__ ((noreturn)); //函数不会返回void centon() __attribute__ ((alias("__centon"))); //设置函数别名,函数是 __centon, 别名是 centonvoid main_enter() __attribute__ ((constructor)); //main_enter 函数在进入 main 函数前调用void main_exit() __attribute__ ((destructor)); //main_exit 函数在 main 函数返回后调用void fun() __attribute__ ((noinline)); //fun 函数不能作为 inline 函数优化void fun() __attribute__ ((section("specials”))); //将函数放到 specials 段中,而不是通常的 text 段中
描述变量属性
- 如果不使用packed属性, 则数组按最小的对齐方式在内存中安排空间, X86平台为4, 结构成员间会有空洞存在
int alivalue __attribute__ ((aligned(32))); //变量所存放的内存地址32字节边界对齐struct domx __attribute__ ((section(“domx”))) = { 0 };int trigger __attribute__ ((section(“MONLOG”))) = 0; //不将全局变量放在默认的data或bss段中, 而指定特定的段中struct zrecord { char id; int zar[32] __attribute__ ((packed)); //紧凑安排数据结构中的成员元素};
描述数据类型属性
struct blockm{ char j[3];}__attribute__((aligned(32))); //此数据类型的变量的内存地址32字节边界对齐int rslt = ({ int a=5; a+3;}); //复合声明返回值(Compound Statements Returning a Value):在一对圆括号中的最后一个表达式所计算的值为返回值, rslt所获得的返回值为8
0 0
- C 扩展关键字
- C扩展 typeof 关键字解释
- C 扩展关键字 typeof 解析
- MSP430 C语言的关键字扩展1
- MSP430 C语言的关键字扩展
- c语言扩展关键字的疑惑
- C51编译器的扩展C语言关键字
- IAR 扩展关键字
- C++ : __attribute__关键字扩展
- __attribute__关键字扩展
- IAR 扩展关键字
- IAR扩展关键字
- IAR 扩展关键字
- IAR 扩展关键字
- IAR之扩展关键字
- IAR 常用扩展关键字
- 关键字const的扩展
- 关键字const的扩展
- C 指针
- Pycharm5注册方式(最新)
- shell学习-16-dirname
- c#设计模式之工厂方法模式
- 欢迎使用CSDN-markdown编辑器
- C 扩展关键字
- 学习日志三
- C 关键字
- HttpServlet 详解(基础)
- vue 跳转不成功
- JVM结构、GC工作机制详解
- Java 对象的生命周期
- Linux系统系能监控(CPU篇)
- Java线程的使用以及中断线程