Skip to main content
MHase
Associate III
October 9, 2019
Question

Is there anything that should considered when using optimization.

  • October 9, 2019
  • 2 replies
  • 754 views

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.

This topic has been closed for replies.

2 replies

TDK
October 10, 2019

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""."
Ozone
Principal
October 10, 2019

> 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.