Reputation: 451
Can you please tell me why the following function func1 is not getting inlined?
Code
#include <stdio.h>
#include <stdlib.h>
static inline int func1(int a) {
return a*2;
}
int main(int argc, char **argv) {
int value = strtol(argv[1], NULL, 0);
value = func1(value);
printf("value: %d\n", value);
return 0;
}
Run
$ gcc -Wall -o main main.c
$ objdump -D main | grep func1
0000000000000700 <func1>:
742: e8 b9 ff ff ff callq 700 <func1>
Upvotes: 0
Views: 145
Reputation: 1922
I believe it is not inlined because one is not doing optimisation, (for debugging, I assume.) From the GCC online docs,
GCC does not inline any functions when not optimizing unless you specify the ‘always_inline’ attribute for the function
Upvotes: 2
Reputation: 1
inline
is literally a mere "suggestion".
Per 6.7.4 Function specifiers, paragraph 6 of the C standard:
A function declared with an inline function specifier is an inline function. 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.
As inline
is just a suggestion, a function with the inline
specifier may or may not be inlined as the implementation determines.
Upvotes: 2