GCC属性

 

gcc扩展功能极多,__attribute__是gcc的关键字,用以描述变量属性,gcc.info中都有详细介绍。

下面举几例内核中常见的:


__attribute__((regparm(0))) int printk(const char * fmt, ...) __attribute__ ((format (printf, 1, 2)));禁止printk使用寄存器传递调用参数,并将printk的参数1作为printf格式串,从参数2开始检查其类型;

void __switch_to(struct task_struct *prev, struct task_struct *next) __attribute__((regparm(3))) ;__switch_to保留3个寄存器用作传递参数;

void __attribute__ ((__section__ (".text.init"))) mem_init();将mem_init编绎到.text.init段;

struct tasklet_head tasklet_vec[32 ] __attribute__((__aligned__((32)),__section__(".data.cacheline_aligned"))) ;将tasklet_vec[32]编绎到.data.cacheline_aligned段,并将它在32字节边界上对齐;

void do_exit(long error_code)__attribute__((noreturn));do_exit不会返回;

struct Xgt_desc_struct { unsigned short size; unsigned long address __attribute__((packed));};将address在结构中紧凑排列。


用__attribute__还可以将一个函数声明为weak, 当没有其他同名函数声明时调用weak, 有其他同名函数时调用其他同名函数.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值