Hi
I have to create a test case where one object is copied to the other when both of the objects have some overlapping memory.
I have experimented with memmove and memcpy and the use of unions.
I am not sure how to use memmove successfully using union members.
at the momemet i have
Code:
#include <string.h>
typedef float float32_t;
typedef int int32_t;
typedef char char_t;
char_t main(int32_t a)
{
char_t Buffer[]= "is this a violation?";
union aUnion /*Violation of Rule 18.2 and 18.4*/
{
int32_t x;
float32_t y;
};
union aUnion test; /*Violation of 18.4*/
test.x=1;
test.y=5.0f;
memcpy(&Buffer[5], &Buffer[10], 10U); /*Possible Violation*/
a=test.x+a;/*Violation value of test.x undefined, x has been overlapped*/
return(Buffer[5]);
}
Memmove above overlaps teh memory of one bject but i require two separate objects to be overlapped!
IS there a way I can use the union members in memcpy and have it compile????
Thanks
Hamish