#include<stdio.h>
#include<stdint.h>
#pragma pack (1)
typedef struct
{
uint16_t x10ms;
uint8_t state; //2 bytes used
}stru1_typedef;
typedef struct
{
uint8_t state;
uint16_t x10ms;
uint8_t state2; //2 bytes used
} stru2_typedef ;
typedef struct
{
uint16_t x10ms;
uint8_t state;
uint8_t state2; //2 bytes used
} stru3_typedef ;
stru1_typedef a[10];
stru2_typedef b[10];
stru3_typedef c[10];
int main(void)
{
uint8_t *p;
printf("%d,%d\n",(uint8_t*)&a[1]-(uint8_t*)&a[0],sizeof(stru1_typedef));
printf("%d,%d\n",(uint8_t*)&b[1]-(uint8_t*)&b[0],sizeof(stru2_typedef));
printf("%d,%d\n",(uint8_t*)&c[1]-(uint8_t*)&c[0],sizeof(stru3_typedef));
a[0].state=0xa5;
b[0].state2=0xa5;
c[0].state=0xa5;
p=(uint8_t *)&a[0];
printf("%d\n",p[2]);
p=(uint8_t *)&b[0];
printf("%d\n",p[3]);
p=(uint8_t *)&c[0];
printf("%d\n",p[2]);
}
编译指令有用的。
|