C inline Keyword
Example
Create a small inline function:
static inline int square(int x) {
return x * x;
}
int main() {
printf("%d", square(5));
return 0;
}
Definition and Usage
The inline keyword is used in front of a function. It suggests to the compiler that the code of the function should be inserted (copied) where the function is called, instead of jumping to the function. This can make small functions a little faster.
It is only a suggestion, and the compiler decides if it follows it. Use inline only for small functions that are called often.
In C, inline functions are usually written as static inline. Without static, you can get an error when the program is built, if the compiler decides not to insert the code.
Related Pages
Read more about inline functions in our C Inline Functions Tutorial.