2022-06-21 07:42 AM
My code is larger than expected and I am close to the 32K program boundary of my device. When I optimize for debugging or have no optimize I cannot test new code.
When I optimize for size I have plenty of room for the new code, but single stepping through the code to find a bug is a problem because the optimization jumps all over the place.
So can I optimize for size the files that I know are good, and optimize for debugging or no optimize the files I am working on?
It appears it is optimize by the whole project. If I change the optimization, it recompiles the whole project to that optimization.
The new rev of the board increases the memory from 32K to 64K but that is not going to happen for a couple of months, and I need this version working before they will release the new board. (Chicken and Egg problem)
Solved! Go to Solution.
2022-06-21 10:58 AM
There are a couple of ways:
1) In the "Project Explorer" window, right-click on a source file (.c or .cpp) and go to "Properties". It will bring up a dialog similar to the general project properties. Under "C/C++ Build" then "Settings" change the optimize settings for that file.
2) You can also force optimization for individual functions by using the "__attribute__((optimize("***")))" string on the function declaration line, where "***" is the type of optimization, for example "Ofast", "Os", "O1", etc. (that is the letter "Oh" not number zero).
__attribute__((optimize("Os"))) void MyFunct( int param )
{
// function code here
}
2022-06-21 10:58 AM
There are a couple of ways:
1) In the "Project Explorer" window, right-click on a source file (.c or .cpp) and go to "Properties". It will bring up a dialog similar to the general project properties. Under "C/C++ Build" then "Settings" change the optimize settings for that file.
2) You can also force optimization for individual functions by using the "__attribute__((optimize("***")))" string on the function declaration line, where "***" is the type of optimization, for example "Ofast", "Os", "O1", etc. (that is the letter "Oh" not number zero).
__attribute__((optimize("Os"))) void MyFunct( int param )
{
// function code here
}
2022-06-21 11:06 AM
So can I optimize for size the project, and optimize for debugging or no optimize the part
#pragma GCC push_options
#pragma GCC optimize ("O0")
your code
#pragma GCC pop_options
but i mean better is debug full project with set optimize for example O3
2022-06-21 03:00 PM
Debugging with optimizations on is hard because the code may not follow your code line for line, and you may not be able to look at a variable that may have gotten optimized out.
When you do not have to debug anymore then it is best to optimize.