As for C, this behavior is undefined. My next suggestion is undefined behavior, but avoids all problems based on types and aliases: use characters.
int a = get_value(); char const * const p = (const char * const)&a; char * q = (char *)0x12345; memcpy(q, p, sizeof(int));
In addition, you can directly access bytes q[i] . (This is part of UB: the q pointer was not obtained as the address of the actual object or as a result of the allocation function. Sometimes this is normal, for example, if you write a stand-alone program that works in real mode and accesses the graphics hardware, you can write to graphics memory directly at the well-known hard-coded address.)
Kerrek SB
source share