Can I use memcpy
to copy data of one data type to another data type...
let's say I have char buffer[1024]
, now I want to copy my struct abc x;
of size 306 (for example) into buffer
..
So Is this legal/possible use without any unexpected behavior?
memcpy(buffer, &x, sizeof(x));
Then there would be any unexpected behavior if I copy back that data to struct abc y;
?
memcpy(&y, &buffer, sizeof(struct abc));
and also if I have struct abc *z
,
z = (struct abc *) buffer;
I try to extract struc abc
from buffer.
I tried my best to explain myself please ignore or suggest if you observe any mistake...