cancel
Showing results for 
Search instead for 
Did you mean: 

Use of inlined functions

herbert
Associate III

Hello,

is there a difference in declaring a C function with the __INLINE resp. inline keyword or using __attribute__((always_inline)) besides the latter one generating a warning?

regards

Herbert

1 ACCEPTED SOLUTION

Accepted Solutions

inline is a standard C function specifier. It's semantics is described in C99 6.7.4, the gist of which is

Making a function an inline function suggests that calls to the function be as

fast as possible. The extent to which such suggestions are effective is

implementation-defined.

In other words, it's only a hint, and the compiler may decide to ignore it, or to implement it only if it's convenient (e.g. inline it only to functions which are in the same source file and only those which are after definition of this function).

__attribute__((always_inline)) is a gcc-specific extension, documented as:

For functions declared inline, this attribute inlines the function independent of any restrictions that otherwise apply to inlining. Failure to inline such a function is diagnosed as an error.

JW

View solution in original post

2 REPLIES 2

inline is a standard C function specifier. It's semantics is described in C99 6.7.4, the gist of which is

Making a function an inline function suggests that calls to the function be as

fast as possible. The extent to which such suggestions are effective is

implementation-defined.

In other words, it's only a hint, and the compiler may decide to ignore it, or to implement it only if it's convenient (e.g. inline it only to functions which are in the same source file and only those which are after definition of this function).

__attribute__((always_inline)) is a gcc-specific extension, documented as:

For functions declared inline, this attribute inlines the function independent of any restrictions that otherwise apply to inlining. Failure to inline such a function is diagnosed as an error.

JW

S.Ma
Principal

I would refrain to use a compiler dependent way.

Making sure a function is inined is for rare use-case.

Besides, the alternative way of inlining functions with #define would be a NO GO (harder debug, breakpoint, etc...)