__attribute__ 用法

来源:互联网 发布:星际皆知你爱我网盘 编辑:程序博客网 时间:2024/06/10 07:41

最近在看项目代码的时候发现了新大陆,之前从没有用过__attribute__,

根据代码和网上看到的资料,总结一下 __attribute__ 的常用用法~


1.__attribute__((packed))取消结构体对齐。

 用例:

typedef struct __attribute__((packed))

{
UBYTE sts;
}ST_USB_POWER_RES;


2.__attribute__((__noreturn__)) 告诉编译器,函数不会返回

 void __throw_bad_typeid(void) __attribute__((__noreturn__));


3.将变量定义在特定位置

static unsigned char  Uart12_Send_Data_Buf [LOG_SEND_BUF_SIZE] __attribute__ ((section (".uncache_edram")))= {0};

原创粉丝点击