Forum Discussion
Altera_Forum
Honored Contributor
11 years agoWrite valid C! - see 'strict aliasing'.
The compiler is allowed to (and will) reorder memory accesses if the types differ (and aren't 'char') even if it is obvious from the source code that they refer to the same physical memory. If you use a 'union' then you'll get the code you expect. The compiler will also sometimes use shifts and optimise away the memory access itself. I'd not thought that int:8 might give a byte-sized item that the compiler doesn't have to assume might alias all other C types.