2023-03-17 04:50 AM
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
Solved! Go to Solution.
2023-03-17 05:29 AM
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
2023-03-17 05:29 AM
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
2023-03-17 05:51 AM
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...)