__attribute__((packed))结构体的成员地址顺序及大小问题

1.验证先定义的成员变量地址是低地址

2.验证__attribute__((packed))结构体的大小是紧凑模式没有填充,4+4+1+4=13个字节大小,32位GCC

#include "stdio.h"
typedef struct  student{


int num;
int score;
char c;
struct student *next;


} __attribute__((packed)) st;




int main(void){


st a,b,*head,*p;
a.num=0x99101;
a.score=0x99;
b.num=0x99102;
b.score=0x80;
head=&a;
a.next=&b;
printf("%p,%p,%p,%p\n",&a.num,&a.score,&a.c,&a.next);
printf("%p,%p,%p,%p\n",&b.num,&b.score,&b.c,&b.next);


printf("%x,%x,%x,%x\n",sizeof(st),sizeof(a),sizeof(b),sizeof(*(a.next)));




return 0;
}


本次运行结果:

[root@andLinux win]# gcc sp.c -o sp &&./sp
0xbfbf965f,0xbfbf9663,0xbfbf9667,0xbfbf9668
0xbfbf9652,0xbfbf9656,0xbfbf965a,0xbfbf965b
d,d,d,d

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值