xxxxxxxxxx
// file test.h
#ifndef TEST_H_INCLUDED
#define TEST_H_INCLUDED
inline int sum (int a, int b)
{
return a+b;
}
#endif
// file sum.c
#include "test.h"
extern inline int sum (int a, int b); // provides external definition
// file test1.c
#include <stdio.h>
#include "test.h"
extern int f(void);
int main(void)
{
printf("%d\n", sum(1, 2) + f());
}
// file test2.c
#include "test.h"
int f(void)
{
return sum(2, 3);
}
xxxxxxxxxx
/*
Inline Functions are functions with a small enough body that
they can be easily substituted at the place where the function
is called. Function substitution is totally compiler choice.
*/
#include <stdio.h>
// Inline C function:
inline int add(int x, int y) {
return x + y;
}
int main() {
int result = add(60, 9); // Inline function call.
printf("Output is: %d\n", result);
return 0;
}
// After compilation:
int main() {
int result = 60 + 9; // Replaced call with operation from function body.
printf("Output is: %d\n", result);
return 0;
}