cancel
Showing results for 
Search instead for 
Did you mean: 

Is there anything that should considered when using optimization.

MHase
Associate II

We have an application with several screens. When I compile my application with optimization 0, then changing screens from one to another is no problem. But when I compile my application with optimization 1, then changing screens causes that application ends in the hardfault_handler. Is there anything that should considered when using optimization.

2 REPLIES 2
TDK
Guru

uninitialized variables

accessing memory past the end of arrays

Likely you need to track down a bug in your code somewhere. Try to figure out where the hardfault occurs and this can help track down the bug.

Optimization by itself does not cause problems, except in cases of compiler bugs which are far less likely than program bugs.

If you feel a post has answered your question, please click "Accept as Solution".

> uninitialized variables

Those should be catched by any good compiler, regardless of optimization (-Wall, "used before initialization").

> accessing memory past the end of arrays

Supposedly not bound to optimization either. But optimizing will usually change the effect of those bugs.

Use a volatile qualifier for variables with external access (invisible to the compiler). Everything an interrupt handler touches is a candidate.

I would start from analyzing the hardfault (SCB registers), and trying to find/debug the exact spot.