Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Digression: inline keyword

inline with functions

The inline calling convention forces a function to be inlined at all call sites.
If the function cannot be inlined, it is a compile-time error.

This what the creator of the Zig language wrote:

Quote

It’s best to let the compiler decide when to inline a function, except for these scenarios:

  • You want to change how many stack frames are in the call stack, for debugging purposes
  • You want the comptime-ness of the arguments to propagate to the return value of the function
  • Performance measurements demand it. Don’t guess!

Otherwise you actually end up restricting what the compiler is allowed to do when you use inline which can harm binary size, compilation speed, and even runtime performance.

So basically he's recommending not to use it unless you have a good and measurable reason to do so.

Other uses of inline

From the official language reference:

Other uses of inline are very different, because they usually allow loops to be evaluated at compile time. I've never used them, since I never felt the need for them, so I can't tell you more.