Forum Discussion
Altera_Forum
Honored Contributor
11 years agoNIOS II Structure Casting w/ Opt. (-O3)
I recently enabled optimization on my NIOS II software (custom telnet server + webserver) and I'm experiencing unexpected behavior. I suspect memory corruption and alignment issues, but I can't seem ...
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.