Hi,
I'm facing a strange behaviour of memcpy function in the below code when compiled with TI compiler version V6.0.2 for the target TMS320F28335.
//-------- Code Starts Here--------------
#include <stdio.h>
float var1;
unsigned int var2;
unsigned long var2;
void main(void) {
var2 = 0x0200;
memcpy(&var1, &var2, 4);
}
//----------Code Ends Here---------------
Issue:
The above code is expected to copy 4 bytes from var2 into var1. However when compiled and executed in target (TMS320F28335) which has 16 bit data in each address, I noticed 8 bytes (4 x 16 bits) are copied from the source to the destination. This results in modifying the contents of unexpected memory address thereby crashing my program. I understood that it was due to incorrect behavior of the memcpy function for a 16bit data in the memory address (Because memcpy assumes the memory address contains 8 bit data and increments the source address 4 times, however it is a 16bit data). Could any one please confirm my understanding is correct? Also please suggest me to use the CGT version in which this issue has been fixed.
Thanks,
Anand