liveBook · Manning

Function call overhead

As explained in Modern C

Function call overhead is the execution cost associated with invoking a function, including possible control-flow transfers, stack handling, and value copying.

A function call can consume more than the function’s own work: execution may reserve stack space, initialize or copy locals, transfer control, and copy a struct return value according to the platform’s calling convention. If caller and callee definitions are visible in the same translation unit, a compiler may inline the callee, removing the call overhead and exposing further optimization opportunities. TAKEAWAY: Inlining removes the call itself, but depends on definition visibility and compiler decisions. section 15.1

Inlining a small C function

The `toto_init` definition checks its argument, initializes the pointed-to object when non-null, and returns the pointer. Placing this definition in a header makes it visible to users that need possible inlining; a separate translation unit can provide the function symbol once.

How Modern C covers it

How deep it goes
Explains stack, control-flow, cache, and return-value costs, then stops short of prescribing compiler-specific inlining behavior.
Examples
Uses `toto_init` to show an inline header definition and a separate one-translation-unit function declaration.
What it assumes
Assumes familiarity with C functions, headers, declarations, definitions, and translation units.
What you can do after
Evaluate when definition visibility can remove call overhead and expose dead-branch or repeated-computation optimizations.
How it connects
Connects function call overhead with inline functions, calling conventions, translation units, compiler optimization, and function definitions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.