typedef struct
{
unsigned char head_first; //包头首字节
unsigned char head_last; //包头末字节
unsigned char ad[5][96][2];
unsigned char end_first; //包尾首字节
unsigned char end_last; //包尾末字节
} pakage_t;
typedef struct
{
unsigned short have;
pakage_t ph_data;
unsigned short NVLL;//凑4字节对齐
}save_pakage_t; //1076Byte
#define ph_base 0XC0000000
#define PhotoLoad ((save_pakage_t *) ph_base)
main.c()
{
uint8_t *p;
uint32_t i;
uint32_t len_array;
pakage_t *rel_addr1[100]; //指针数组
pakage_t *rel_addr2[100]; //指针数组
pakage_t *abs_addr; //绝对地址
abs_addr = (pakage_t*)(0XC0010000);
len_array = sizeof(pakage_t);//len_array= 0X3C4
//PhotoLoad 赋值
for(i=0;i<100;i++)
{
p = (uint8_t*)&PhotoLoad[i].have;
for(uint16_t j=0;j<sizeof(pakage_t);j++)
*(p++) = i;
}
for(uint8_t i=0;i<100;i++)
{
abs_addr[i] = PhotoLoad[i].ph_data; //拷贝数据(将整个ph_data拷贝,地址: 0XC0010002+i*sizeof(pakage_t)
rel_addr1[i] = &PhotoLoad[i].ph_data; //指针数组赋值
rel_addr2[i] = &abs_addr[i]; //指针数组赋值
}
}
rel_addr1 相邻之间相差sizeof(save_pakage_t)
rel_addr2 相邻之间相差sizeof(pakage_t)
整理如下:
从上可以看出,地址转换到数据,数组加一,地址加整个结构体长度。也就是说地址下标代表整个结构体类型数据