liveBook · Manning

Inline function

An inline function is a function defined or designated for incorporation at its use site, either syntactically or through compiler substitution, rather than necessarily invoked through an ordinary call.

How 4 Manning books explain it

Modern C

inline is a C function specifier that permits a function definition to be suitable for direct integration into callers without changing its semantics.

How it is used
Uses inline functions to expose optimization opportunities and provide type-safe alternatives to suitable function-like macros.
How deep it goes
Explains call replacement, definition visibility, header-based instantiation, and the costs of static header functions.
Examples
Uses an unsigned square, a header-defined initializer, and a type-generic floating-point minimum.
What you can do after
Apply it by defining header-visible functions, arranging an instantiation, and choosing functions over suitable macros.

Read how Modern C explains inline function →

Modern C, Third Edition

inline is a C function specifier that permits a definition to suggest inline substitution of a function's body at call sites without requiring the compiler to perform that substitution.

How it is used
Uses inline functions to expose small function bodies for optimization and provide type-safe alternatives to function-like macros.
How deep it goes
Explains call overhead, optimization opportunities, header definitions, and a single-translation-unit instantiation pattern.
Examples
Illustrates a header-defined initializer and contrasts a squaring function with a macro that evaluates count() twice.
What you can do after
Evaluate whether inline suits a small function and measure any claimed performance improvement.

Read how Modern C, Third Edition explains inline function →

Kotlin in Action, 2E

An inline function is a Kotlin function whose body can be substituted at its call sites by the compiler and which can declare reified type parameters.

How it is used
Enables efficient higher-order helpers and collection operations while permitting non-local returns from their lambdas.
How deep it goes
Explains call-site bytecode substitution, lambda restrictions, performance tradeoffs, and reified runtime type checks.
Examples
Uses a locking helper, collection filter/map operations, and filterIsInstance on a mixed String and Int list.
What you can do after
Apply it via Kotlin inline and reified declarations to design small lambda-taking helpers and runtime type checks.

Read how Kotlin in Action, 2E explains inline function →

Grokking Simplicity

A function defined at the place in a program where it is used rather than assigned to a separate name.

How it is used
Uses short anonymous callbacks directly with higher-order functions such as map and withLogging.
How deep it goes
Defines inline, anonymous, global, and local functions, then demonstrates callbacks and refactoring limits.
Examples
Uses customer emails, greetings, logging, and purchase filtering and mapping to demonstrate inline callbacks.
What you can do after
Apply inline functions as map callbacks and recognize when naming a function improves reuse and clarity.

Read how Grokking Simplicity explains inline function →

What to know first

Related concepts

Questions about inline function

What is inline function?

An inline function is a function defined or designated for incorporation at its use site, either syntactically or through compiler substitution, rather than necessarily invoked through an ordinary call.

Which Manning books explain inline function?

Modern C, Modern C, Third Edition, Kotlin in Action, 2E and Grokking Simplicity.

What should I know before learning inline function?

Manning books that teach inline function usually introduce calling convention, data conversion, function type and header file first.

What is the difference between inline function and function-like macro?

An inline function is a function defined or designated for incorporation at its use site, either syntactically or through compiler substitution, rather than necessarily invoked through an ordinary call. A function-like macro is a macro invoked with function-like syntax that accepts token input and expands or transforms it into generated source.

What kinds of inline function are there?

Kinds of inline function include filtering.

What is inline function a kind of?

Inline function is a kind of function. A function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.