Yes, you should use memcpy
, not pointer conversion, for exactly the reason you discuss: alignment. Converting pointers is not safe. If the alignment is wrong, the behavior when you use the resulting pointer is not guaranteed by the C standard.
An alternative in some situations is to read the data directly into the object.