### Inlining

Carbide supports inlining C/C++ functions that you define with the inline, __inline__, or __inline specifier keywords.

The following functions are never inlined:

- Functions that return class objects that need destruction.
- Functions with class arguments that need destruction.
- Functions with variable argument lists.

The compiler determines whether to inline a function based on the ANSI Strict, Inline Depth, Auto-inline, and Deferred Inlining settings.

TIP When you call an inlined function, the compiler inserts the actual instructions of that function rather than a call to that function. Inlining functions makes your programs faster because you execute the function code immediately without the overhead of a function call and return. However, it can also make your program larger because the compiler may have to repeat the function code multiple times throughout your program.

If you disable the ANSI Keywords Only setting, you can declare C functions to be inline.

##### Table 1: Settings for the Inline Depth

This setting | Does this…
--- | ---
Don’t Inline | Inlines no functions, not even C or C++ functions declared inline.
Smart | Inlines small functions to a depth of 2 to 4 inline functions deep.
1 to 8 | Inlines to the depth specified by the numerical selection.

The Smart and 1 to 8 items in the Inline Depth dropdown menu correspond to the pragma inline_depth (inline_depth). To check this setting, use __option(inline_depth), described at Checking Settings.

The Don’t Inline item corresponds to the pragma dont_inline. To check this setting, use __option (dont_inline). By default, this setting is disabled.

The Auto-Inline setting lets the compiler choose which functions to inline. Also inlines C++ functions declared inline and member functions defined within a class declaration. This setting corresponds to the pragma auto_inline. To check this setting, use __option (auto_inline). By default, this setting is disabled.

The Deferred Inlining setting tells the compiler to inline functions that are not yet defined. This setting corresponds to the pragma defer_codegen. To check this setting, use __option (defer_codegen).

The Bottom-up Inlining settings tells the compiler to inline functions starting at the last function to the first function in a chain of function calls. This setting corresponds to the pragma inline_bottom_up. To check this setting, use __option (inline_bottom_up).

You can also disable automatic inlining of specific functions within a source file using the __attribute__((never_inline)).

##### Example __attribute__(never_inline)

inline int f() __attribute__((never_inline))
{
return 10;
}

int main()
{
return f(); // f() is never inlined
}

NOTE For Intel x86 targets, the __decspec(noinline) is a compatible synonym.