Search⌘ K
AI Features

Inline Functions

Explore the concept of inline functions in C to improve program efficiency by reducing the overhead of frequent small function calls. Understand how the inline keyword suggests to the compiler to expand code at the call site and learn why combining static with inline prevents linker errors in single source files, ensuring safer modular code development.

In previous lessons, we defined and called functions in the usual way: the program transfers control to the function, executes its body, and then returns to the caller. For small functions that are called frequently, this process can introduce slight overhead because each function call requires transferring control to another location in the program.

What is an inline function?

C99 introduced the inline keyword, which allows the compiler to expand the function’s code directly at the point where it is called. This can improve efficiency for small helper functions.

An inline function is declared using the inline keyword:

inline returnType functionName (param1Type param1Name, param2Type param2Name) {
function_statement1;
function_statement2;
return returnVar;
}
Blueprint of an inline function

Note that its declaration is exactly the same as a regular function, just with an ...