有时在跨架构porting的时候,如X86 To ARM, 内存的对齐问题并非如我们所愿,所以在用Gcc compiler的时候,要尽量使用__attribute__ ((__packed__)),比如:

struct ib_net_radio_t {
unsigned char word[2];
unsigned char packet;
unsigned char check;
unsigned char proto[2];
unsigned char payload[0];
}__attribute__ ((__packed__));

在ARM下用Gcc 2.9编译,如果不加上__attribute__ ((__packed__)),sizeof(struct ib_net_radio_t) == 8,加上之后,就是6. 在转packet的format的时候,这个得分外注意。

Tags: ,