C Inline Functions

Beginner
6 min read
Updated: Nov 2026
1 example

What Is Inline Functions?

inline (C99) is a hint that a function is cheap enough to expand at the call site, avoiding call overhead. The compiler may ignore it. Put static inline functions in headers to avoid linker problems, and prefer them over function-like macros for type safety.

Remember
static inline int square(int x) {
    return x * x;
}

Cheat Sheet

Keep these facts handy while you work with Inline Functions in C.

TopicDetail
Keywordinline, C99 and later
In headersUse static inline
Versus macroType checked, evaluates arguments once
GuaranteeNone; it is only a hint

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Variable Scope.

Example 1 — Small helpers marked inline

Behavior is the same as a normal function.

C
#include <stdio.h>

static inline int square(int x) { return x * x; }
static inline int max2(int a, int b) { return a > b ? a : b; }

int main(void) {
    int i = 3;
    printf("square(7) = %d\n", square(7));
    printf("max(4, 9) = %d\n", max2(4, 9));
    int r = square(i++);
    printf("square(i++) = %d, i = %d\n", r, i);
    return 0;
}

How It Works

  1. static inline keeps one private copy per file.
  2. Unlike a macro, square(i++) evaluates i++ exactly once, so 3 * 3 = 9.
  3. Afterwards i is 4. A macro #define SQUARE(x) ((x)*(x)) would increment twice and be undefined.

Edge Cases & Pitfalls

Check these before relying on Inline Functions in real programs.

link

Plain inline in a header

In C99 a non-static inline needs one external definition elsewhere or you get undefined-reference errors. Use static inline.

big

Inlining everything

Large inlined functions bloat code size. Let the optimizer decide.

Key Takeaways

  • Hint: the compiler decides.
  • Header: use static inline.
  • Macros: prefer inline functions for typed helpers.

One line: inline (C99) is a hint that a function is cheap enough to expand at the call site, avoiding call overhead.

Frequently Asked Questions

Sometimes. It removes call overhead for tiny functions, but optimizing compilers already inline many small functions at -O2 without the keyword.
Inline functions have types, scope, and evaluate arguments once. Macros are textual substitution and can evaluate arguments multiple times.
Continue with "C Variable Scope" next. Where a name is visible: block, function, and file scope. The C Functions hub lists every topic in order.

Next: Variable Scope

Where a name is visible: block, function, and file scope.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful