Optimization level causes undesired code output

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Optimization level causes undesired code output

837 次查看
manasvb
Contributor III

Am using lpc55s69.

For debug config, optimization level is None, while for release it is -Os(size optimization).

Because of this I get different code behaviour in debug and release. For release mode, I tried all the optimization levels, but I get same output, only when I disable the optimization I get correct output.

 

I dont want to disable optimization in Release and also want correct behaviour, how do I achieve this.

标签 (1)
0 项奖励
回复
1 回复

827 次查看
ErichStyger
Specialist I

I'm afraid that you have to debug your 'wrong' code why it is failing. My experience these days is that if the output is wrong in higher optimization levels, it is likely a programming error (race condition, dangling pointers, wrong usage of memory, buffer overflow, ...).

What I recommend is that you carefully check compiler warnings, and that you increase the warning level to a 'pedantic' one. This should give you some hints.

The other approach is that you start reducing your application, to get a 'minimal failing example', to isolate the issue.

Last but not least, have a read at https://www.whyprogramsfail.com/

Good luck!

Erich

0 项奖励
回复