tdmicro
Newbie level 1
hi,
we are trying to copy some data in a structure (IDE :keil , lang - cpp)
structure
and the copying function is
rxData.ubData[] value is 7,8,9,10,11,12,13,14
while copying from rxData.ubData[] to dataID, in watch window, we can see the following details
dataID-> pD= 7;
dataID-> sD= 8;
dataID-> dD= 9;
dataID-> txdata= 00 13 12 11;
but expected value is
dataID. txdata= 13 12 11 10;
while debuging the code, 3rd index value of rxData.ubData 10 is missing. so we thought it is because of structural padding and used #pragma pack(1)
then we are getting exception (classB_trap)
kindly help us to find out the mistake in the above code
we are trying to copy some data in a structure (IDE :keil , lang - cpp)
structure
Code:
typedef unsigned char U8;
typedef struct
{
U8 pD;
U8 sD;
U8 dD;
U8* txdata;
}data_ID;
typedef struct
{
sObj Data;
unsigned char ms;
unsigned char status;
}zmtData;
typedef struct //autogenerated structure
{
ubyte cG;
ulong uD;
ulong uk;
ubyte ubData[8];
uword cR;
}sObj;
and the copying function is
Code:
Len=4;
sObj rxData;
data_ID *dataID = (data_ID *)malloc(sizeof(U8)*(Len+3));// Allocate memory for struct data_ID
dataID->txdata = (U8*)malloc(sizeof(U8)*Len);
read_data(&rxData);
/*
rxData.ubData value is 7,8,9,10,11,12,13,14
*/
memcpy(dataID,rxData.ubData, sizeof(data_ID));//dataID=(data_ID*)rxData.ubData;
rxData.ubData[] value is 7,8,9,10,11,12,13,14
while copying from rxData.ubData[] to dataID, in watch window, we can see the following details
dataID-> pD= 7;
dataID-> sD= 8;
dataID-> dD= 9;
dataID-> txdata= 00 13 12 11;
but expected value is
dataID. txdata= 13 12 11 10;
while debuging the code, 3rd index value of rxData.ubData 10 is missing. so we thought it is because of structural padding and used #pragma pack(1)
then we are getting exception (classB_trap)
kindly help us to find out the mistake in the above code