随机属性 c语言代码,C语言的属性:__attribute__

1. 变量的属性

详细内容参考:变量的属性

注:

1)_attribute_后面必须为两对括号:((…))

2)属性关键字的前后也可加“_”,如aligned可为__aligned_

1.1 对齐(aligned (alignment))

指定变量或结构域的起始地址对齐(以字节为单位):

int x __attribute__ ((aligned (16))) = 0; // 16字节对齐

struct foo

{

int x[2] __attribute__ ((aligned (8))); // 8字节对齐

};

// ask the compiler to align a variable or field to

// the maximum useful alignment for the target machine you are compiling for

short array[3] __attribute__ ((aligned));

1.2 紧凑型 (packed)

变量或结构域以最小对齐单位对齐,如变量以字节对齐,结构域以位对齐:

struct foo

{

char a;

int x[2] __attribute__ ((packed)); // it immediately follows a

};

1.3 指定代码段(section (“section-name”))

把变量或函数放于指定的代码段:

struct duart a __attribute__ ((section ("DUART_A"))) = { 0 };

struct duart b __attribute__ ((section ("DUART_B"))) = { 0 };

char stack[10000] __attribute__ ((section ("STACK"))) = { 0 };

int init_data __attribute__ ((section ("INITDATA"))) = 0;

main()

{

/* Initialize stack pointer */

init_sp (stack + sizeof (stack));

/* Initialize initialized data */

memcpy (&init_data, &data, &edata - &data);

/* Turn on the serial ports */

init_duart (&a);

init_duart (&b);

}

1.4 向量尺寸(vector_size (bytes))

指定向量的大小,以字节为单位:

int foo __attribute__ ((vector_size (16)));

int foo __attribute__ ((__vector_size__ (16)));

struct S { int a; };

struct S __attribute__ ((vector_size (16))) foo;

2. 函数的属性

详细内容参考:函数的属性

3. 类型的属性

详细内容参考:类型的属性

typedef int more_aligned_int __attribute__ ((aligned (8)));

typedef long HEXAGON_VecPred128 __attribute__((__vector_size__(128)))

__attribute__((aligned(128)));

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值