Search code examples
optimizationcompiler-optimizationxc16

How to switch the optimization level of the compiler partially for every function?


How can I switch the optimization level of my compiler (xc16) on a different level for each function?

for example:

void _ISR _T1Interrupt    //compile with O0
{
.....
}

int_16_t main (void)         //compile with O2
{
.....
}

Solution

  • I find the solution:

    __attribute__((optimize("-O0"))   //optimization for the next function is O0
    void _ISR _T1Interrupt            //compile with O0
    {
    .....
    }
    
    __attribute__((optimize("-O2"))   //optimization for the next function is O2
    int_16_t main (void)              //compile with O2
    {
    .....
    }