The general answer when asking "how does one implement memcpy function conformant with strict aliasing rules" is something along the lines of
void *memcpy(void *dest, const void *src, size_t n)
for (size_t i = 0; i < n; i++)
((char*)dest)[i] = ((const char*)src)[i];
The strict aliasing rule specifically excludes casts to
char types (see last bullet point below), so the compiler will do the correct thing in your case. Type punning is only a problem when converting things like
short. Here the compiler may make assumptions that will cause undefined behavior.
An object shall have its stored value accessed only by an lvalue expression that has one of the following types:
- a type compatible with the effective type of the object,
- a qualiﬁed version of a type compatible with the effective type of the object,
- a type that is the signed or unsigned type corresponding to the effective type of the object,
- a type that is the signed or unsigned type corresponding to a qualiﬁed version of the effective type of the object,
- an aggregate or union type that includes one of the aforementioned types among its members (including, recursively, a member of a subaggregate or contained union), or
- a character type.