这样试试:
byte *p = tUartCom ->Data;
for(i=0; i<Len; i++)
{
*p++ = *Data++;
}
另:
tDataCom->End1 = tDataCom->Data + tUartCom->Length;
tDataCom->End2 = tDataCom->End1 + 1;
tDataCom->End3 = tDataCom->End2 + 1;
只从上面几句看,End1、End2和End3是由tDataCom->Data算来的,无必要在结构里定义。
这样将tDataCom->Data变成结构的最后一个成员,变成一个柔性数组。如:
typedef struct
{
byte Head;
byte Length;
byte Cmd;
byte Data[];
} SturctComData;
uint8_t buf[5] = {0x11, 0x12, 0x13, 0x14};
uint8_t TxBuf[20] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
SturctComData *tDataCom = (SturctComData*)TxBuf;
uint8_t *Data = buf;
uint8_t *p = tDataCom->Data;
int i;
for (i=0; i<4; ++i)
*p++ = *Data++;
for (i=0; i<7; ++i)
printf("0x%02x ", TxBuf[i]); //结果:0x01, 0x02, 0x03, 0x11, 0x12, 0x13, 0x14