On this page
inline
Prev: extern | Up: builtins | Next: restrict
Rel: Preprocessor & Macros
Ref: cppreference — inline
Tags: #public #prog #c #builtins #tier/standard
Availability
Built-in (Function Specifier (C99)) — requires no #include header.
Syntax & Overview
static inline T fn(void) { ... }
Hints the compiler to inline a function body; combine with static in headers (static inline) to avoid multiple-definition linker errors.
Notes & Pitfalls
- In headers, always use
static inline: Bareinlinein C99 has different linkage rules than C++ and causes linker errors unless anextern inlinedefinition exists in one.cfile.
Example
#include <assert.h>
static inline int clamp(int x, int lo, int hi) {
return x < lo ? lo : (x > hi ? hi : x);
}
int main(void) { assert(clamp(15, 0, 10) == 10); }
Linked from
Related notes
- tuts/c/builtins/extern Linked here; links to this page; shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/restrict Linked here; links to this page; shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins Linked here; links to this page; shared tags: #builtins, #c, #prog
- tuts/c/compilation_and_internals/preprocessor_and_macros Linked here; shared tags: #c, #prog
- tuts/c/builtins/__FILE__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__func__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__LINE__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__STDC_VERSION__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/_Alignof shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/_Atomic shared tags: #builtins, #c, #prog, #tier