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