Hallo
I have been looking into compiler optimazation. My project has a level of 0 - No optimazation As I can read from the help file, default is level 2. Using level 2 will decrease the size but also remove the possiblity to debug. Thats ok for released version of the software.
But are there any benefits, other then smaller code size, using compiler optimazation? I mean, is there any performance gain ? Better interrupt respons etc? I don't have any problem fitting un-optimized code into the flash.
But if using optimazation makes it hard to debug, then its difficult to "debug" any problems caused by the optimazation? Is there any gurantie, that if the code work with no optimazation, then its behaves the same with optimazations on??
/Thomas
The optimization will not just change the code size, but also the execution speed.
So, there can be no warranty at all that a program that works without optimization will also work with optimization enabled - or the reverse.
Because of this, you must perform all testing using the same compiler settings that you will use when releasing your applciation for production.
But are there any benefits, other then smaller code size, using compiler optimazation? I mean, is there any performance gain ? Better interrupt respons etc?
Those are the exact reasons for doing optimization. If you are satisfied with code size and performance of your application at optimization level 0, you don't need to recompile it at higher optimization levels. There is more to it. Raising optimization level can trigger bugs in the code that don't show at lower optimization levels. So by staying at optimization level 0 you can skip the extra testing required to find those bugs (saves you time.) But if you must maintain that code long-term, you'll probably want to use every opportunity to find bugs, so raising optimization level could be a good idea.
But are there any benefits, other then smaller code size, using compiler optimazation?
Quite possibly, yes.
I mean, is there any performance gain ?
Definitely.
Better interrupt respons etc?
Quite possibly.
But if using optimazation makes it hard to debug, then its difficult to "debug" any problems caused by the optimazation?
It's usually fairly easy to tell whether a problem is caused directly by the compiler optimizations, since it will disappear at a lower optimization setting. A more detailed analysis usually required a look at the assembly output for the passage in question.
Is there any gurantie, that if the code work with no optimazation, then its behaves the same with optimazations on??
No, there's no such guarantee. In fact, as far as issues like timing are concerned, it's safe to assume that the optimized code will behave differently.
No, that is not true.
It may well make source-level debugging more tricky - but it is by no means impossible!
Thanks for all the comments.. Its know more clear to me.
Is there any guide lines or best practice, for stuff to avoid when using optimazation? - to make the debug a bit more easy? Any things to avoid or to diffrent?
Yes:
Getting the Least Out of Your C Compiler Class #508, Embedded Systems Conference San Francisco 2001 Jakob Engblom
user.it.uu.se/.../engblom-esc-sf-2001.pdf