4.16 inline Pragma

The IAR inline pragma ensures that the following function is either in-lined or not in-lined, based on the pragma parameter.

Suggested Replacement

There is no equivalent MPLAB XC8 pragma, but there are attributes that perform similar tasks.

Use the always_inline attribute to ensure a function is in-lined; use the noinline attribute to prevent in-lining from taking place.

Caveats

When indirectly calling a function using the always_inline attribute, the compiler might or might not in-line it depending on the current optimization level, and a failure to in-line such a call might or might not be reported.

Examples

Consider migrating IAR code such as:
volatile int x;
#pragma inline=forced
void foo(void) {
    x++;
}


#pragma inline=never
void __attribute__((noinline)) bar(void) {
    x--;
}
 
int main() {
    foo();
    bar();
    return 0;
}
to MPLAB XC8 code similar to:
volatile int x;
void __attribute__((always_inline)) foo(void) {
    x++;
}
 
void __attribute__((noinline)) bar(void) {
    x--;
}
 
int main() {
    foo();
    bar();
    return 0;
}

Further Information

See the Function Specifiers section in the MPLAB XC8 C Compiler User's Guide for AVR MCUs for more information on these specifiers.