我有这个结构,但知道每4个字节没有在内存中使用,我需要在内存中正确地对齐结构。我不太清楚该怎么做,虽然我知道我应该这么做,我也知道它需要在哪里发生。
typedef struct _vol_meta {
uint16_t crc; // 2 bytes
uint8_t ver_major; // 1 byte
char pad1; // need to align here - 1 byte
uint16_t size; // 2 bytes
uint8_t ver_minor; // 1 byte
char pad2; // need to align here - 1 byte
uint8_t pagenum; // 1 byte
uint8_t rownum; // 1 byte
char pad3[2]; // align here - 2 bytes
uint8_t name[15]; // 15 bytes
// not sure how I'm supposed to align the array of uint8_t vars?
} VOL_META;有什么c数据类型像
align 2它告诉编译器跳过接下来的两个字节或其他什么?有点迷路了。
发布于 2015-11-25 22:08:48
可以使用(意外)“对齐”属性,如下所示:
__属性__ ((对齐(2)) //字对齐
xc16用户指南第8.12节是您的朋友。
https://stackoverflow.com/questions/33926490
复制相似问题