2014年12月8日 星期一
struct mapping
__attribute__((packed)); need to be added otherwise it may cause memory alignment issue
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct test {
uint8_t sig[4];
uint8_t len;
uint8_t mic_sig[5];
uint32_t vid;
uint16_t did;
uint16_t idxx;
} __attribute__((packed));
int main(){
uint8_t test_string[]={'K','I','D','O',0x40,'M','i','T','A','C',0x86,0x80,0x02,0x3c,0x86,0x81,0x01,0x3c};
struct test *info=(struct test *)test_string;
printf("sig=%.4s len=0x%x mic_sig=%.5s vid=0x%04x did=0x%04x idxx=0x%04x\n" ,info->sig, info->len, info->mic_sig, info->vid, info->did, info->idxx);
return 0;
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言