Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inline a function inside another inline function in C

Tags:

c

function

inline

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).

like image 675
gramm Avatar asked Jun 30 '10 08:06

gramm


People also ask

Can an inline function call another inline function?

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.

Can we extern inline function in C?

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.

What is __ inline in C?

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.

What is #pragma inline in C?

#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.


1 Answers

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.

like image 108
Paul R Avatar answered Nov 13 '22 17:11

Paul R