We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Has anyone seen problems were sections of code will not execute when compiled at different optimization levels? For example, we have and application that is run from a menu structure through the UART. When different parts of the code seem to behave incorrectly, changing the optimization level from 8 to 9 or 9 to 8 will often solve the problem. I've also had conditions where removing a single character from a printf solved the problem. If anybody has seen this, have you figure out what may be causing this strange behavior. -Thanks
All sorts of problems might exhibit this symptom. In a wild guess at a rough order of probability: When you change the optimization level, you change the code size. Lots of things might move around. If you have an uninitialized/dangling/corrupted pointer and are stepping on data or code, you could see this behavior. Similarly, removing a character from a printf() format string moves all your data following that string by one byte, shifting the value that you clobber. Try rearranging the link order of your modules, without changing the code. If the problem goes away or the symptoms change, start hunting for that address that gets clobbered. Different optimization levels also lead to different execution times through the code. If you have timing sensitive code, or have some race conditions improperly controlled via semaphores / interrupt masking / etc, you could see this symptom. If there were a bug in the optimizer, you might see this behavior. Scrutinize the assembler output and look for functional differences in the output for the affected routines.