Slightly vague question I know... I have written quite a long control algorithm in C for an embedded processor. The default build setting is zero optimization, and that is what I have been using up until now. The programme works perfectly as far as I can tell. I get no compiler errors or warnings. I have also compiled parts of the algorithm in CodeBlocks using the gcc compiler with the "wall" of warnings enabled and I get no warnings at all. Today, I cranked up the optimization options to allow a faster sampling frequency. However, the code no longer works as intended. It doesn't crash, it's just some of the outputs are not as expected.
What sorts of problems are associated with optimized code that may be hidden during an un-optimized build? Any variables that are accessed by ISRs are declared as volatile as I was concerned that they may be getting optimized away but that doens't seem to be the issue. I've read that optimized code may pack arrays closer together so if you accidentaly increment a pointer too much it can cause an issue. I doubt that the mathematics of my algorithm would work at all if that were the case. What else should I be looking for?
What sorts of problems are associated with optimized code that may be hidden during an un-optimized build? Any variables that are accessed by ISRs are declared as volatile as I was concerned that they may be getting optimized away but that doens't seem to be the issue. I've read that optimized code may pack arrays closer together so if you accidentaly increment a pointer too much it can cause an issue. I doubt that the mathematics of my algorithm would work at all if that were the case. What else should I be looking for?