632Inline Functions in C
The keyword inline, when applied to functions, tells the compiler to optimize calls to the functions. Usually used for short functions and for the sake of clarity.
inline int max(int a, int b) {
return a + b;
}
int main(void) {
int x = 2;
int y = 6;
printf("result: %d", add(x,y));
}
// ok, the example is stupid, but i hope it illustrates the idea
Looks exactly the same as calling a function, but actually the function is not called, no function-calling overheads are created. Instead the inline function is expanded in place, where it is called. Obviously this only makes sense with rather short functions.