I currently have inline functions calling another inline function (a simple 4 lines big getAbs()
function). However, I discovered by looking to the assembler code that the "big" inline functions are well inlined, but the compiler use a bl
jump to call the getAbs()
function.
Is it not possible to inline a function in another inline function? By the way, this is embedded code, we are not using the standard libraries.
Edit : The compiler is WindRiver, and I already checked that inlining would be beneficial (4 instructions instead of +-40).
The only way to force code to be inline is to, well, write it inline. But, even, then the compiler may decide it knows better and decide to shift it out to another function. It has a lot of leeway in generating executable code for your particular source, provided it doesn't change the semantics of it.
Similarly, if you define a function as extern inline , or redeclare an inline function as extern , the function simply becomes a regular, external function and is not inlined. End of C only.
The __inline keyword suggests to the compiler that it compiles a C or C++ function inline, if it is sensible to do so. The semantics of __inline are exactly the same as those of the inline keyword. However, inline is not available in C90. __inline is a storage class qualifier.
#pragma inline declares a function to be expanded inline. - #pragma noinline declares a function whose inline expansion is to be stopped when the -Oinline_level option is used. - If both #pragma inline and #pragma noinline are specified for the same function within a single translation unit, an error will occur.
Depending on what compiler you are using you may be able to encourage the compiler to be less reluctant to inline, e.g. with gcc you can use __attribute__ ((always_inline))
, with Intel ICC you can use icc -inline-level=1 -inline-forceinline
, and with Apple's gcc you can use gcc -obey-inline
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With