单字节对齐

 
 
一、Visual Studio环境、Keil环境
#pragma pack (1)
 
二、Linux环境gcc
#define PACKED __attribute__((packed))
struct PACKED Gprs
{
 unsigned short head;
 unsigned char flag;
};
 
typedef struct _UsrPhrase
{
   
    char key;
    int x;

} __attribute__((packed)) UsrPhrase;

struct __attribute__((packed)) GprsWeight
{
unsigned short head;
unsigned char flag;
unsigned char company;
unsigned short addr;
unsigned short driver;
unsigned int weight;
unsigned int time;
unsigned int package;
unsigned char checksum;
};

 

posted @ 2012-03-15 09:47  虚幻  阅读(827)  评论(0编辑  收藏  举报