|
发表于 2011-9-1 18:43:17
|
显示全部楼层
pnumber 结构中成员的地
pSur_Struct 源结构首地址
pDest_Struct 目的结构首地址
SetValu(void * pnumber,void * pSur_Struct,void * pDest_Struct,int size)
{
memcopy( (void *)(((char*)pDest_Struct)+((char*)pnumber-(char*)pSur_Struct)),pnumber,size);
}
如:
typedef struct
{
int x1;
int x2;
int x3;
int x4;
char x5;
long x6;
double x7;
}struct_A; // 可以是任意复杂结构
struct_A A,B,C;
SetValu(&A.x5,&A,&B,sizeof(A.x5)); // B.x5 = A.x5; //会计算出合适的偏移地址,赋值之
SetValu(&A.x6,&A,&B,sizeof(A.x6)); // B.x6 = A.x6;
SetValu(&C.x2,&C,&A,sizeof(C.x2)); // A.x6 = C.x2;
SetValu(&C.x7,&C,&A,sizeof(C.x7)); // A.x6 = C.x7;
适用于小端系统 |
|