you can use the always_inline attribute, for example:
void foo () __attribute__((always_inline));
From docs
always_inline Functions are generally not built-in unless optimization is specified. For functions declared inline, this attribute even if the optimization level is not specified.
Note1 : there is no need to use inline if you use the always_inline attribute
Note 2 . If the function cannot be inlined, you will receive a warning if, for example, the definition is not available at compilation, with higher optimization gcc can still embed it in the caller, there is a special switch for this:
-funit-at-a-time
From docs :
The optimization levels of -O2 and higher, in particular, allow the unit-at-time mode, which allows the compiler to view information obtained from later functions in a file when compiling a function . Compilation of several files at once into one output file in unit-at-time mode allows the compiler to use the information obtained from all files when compiling each of them .
Note3 : There is no need to have an explicit prototype so you can use the attribute for the defintion function:
__attribute__((always_inline)) void foo() {
Also see this discussion , it answers some of your questions.
iabdalkader Nov 05 '12 at 8:25 2012-11-05 08:25
source share