Is disrespecting alignment requirements undefined behavior?

  alignment, c++

Picture I’m developing for an embedded device so I interact with hardware addresses directly.

I have a uint16_t and I write it to address 0x10001 using (uint16_t*)(0x10001) = myShort;.

What happens in practice on common architectures ? What are the guarantees ?

What if I then try to read it using uint16_t myShortOrIsIt = *((uint16_t*)(0x10001)); ?

Source: Windows Questions C++

LEAVE A COMMENT