This is technically undefined behavior, and the standard does not talk about the results of alias pointers like this. A standard pedant would say that invoking undefined behavior in this way can lead to anything from corrupted data to a system crash in Ragnarok.
Pragmatically, it depends on your equipment. Most modern systems (for example, x86, x64, PPC, MIPS, ARM) process word size records in the form in which you describe, except that writing to a non-primary address will lead to failure. Moreover, this is when the principle of fate comes into force; on a small system
char foo[4]; *((uint_32*)(foo)) = 0x01020304;
The short answer is that itβs not safe if you donβt know exactly what hardware your program will run on.
If you control the hardware for which you are compiling, you can predict what the compiler will do; I used this trick to speed up the packing of byte arrays on embedded systems.
source share