C99 supports inline
functions. The programmer can indicate to the compiler
that a function's speed is critical by marking it
inline
:
inline int square(int x) { return x * x; }
If this definition is in scope, and you make a call to it, the compiler may choose not to translate the C call into a machine-code call, but instead replace it with a copy of the function, thus avoiding the overhead of true call.
Inline function definitions can (and often should) appear in header files instead of their prototypes. A normal (‘external’) definition must still be provided — for example, some part of your program may try to obtain a pointer to the function, and only a normal definition can provide that.
If the inline definition is in scope, an equivalent
external definition can be generated from it by simply
re-declaring the function with extern
:
extern int square(int x);
If the inline definition isn't in scope, you could provide a normal definition which doesn't actually match the inline definition — but this could lead to confusing behaviour.
Java doesn't have explicit inline functions, but virtual machines are permitted to inline functions automatically at runtime.