inline C99 inline function specifier
inline C99 inline function specifier
C99's inline suggests expansion without guaranteeing it or speed. static inline gives internal linkage and avoids missing external definitions.
| Category | Function-related |
|---|---|
| Kind | Keyword / Statement |
| C standard | C99 |
📝 Syntax
inline int add(int a, int b) { return a + b; }
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
sum = 5
⚠️ Warning The example deliberately uses static inline: static provides internal linkage, avoiding the missing linkable external definition that can arise under C99 when only an external inline definition is present. GCC still decides whether to expand the call.
🏷️ Related function keywords
📚 Related Tutorials
❓ FAQ
QIs an inline function always expanded?
ANo. inline is only a specifier; the compiler decides based on factors such as optimization level, function size, and call context. Non-expansion is not an error, and performance should be assessed by measurement.
QWhy does a single-file inline example still need static?
Astatic inline gives the function internal linkage and a complete usable definition in the current translation unit. This avoids missing definitions caused by external inline-definition rules and also works well in headers used by multiple translation units.
QWhich is safer, an inline function or a function-like macro?
AAn inline function has normal type checking and scope, and each argument is evaluated only once, so it is generally safer. A function-like macro remains text substitution and may evaluate arguments multiple times or suffer precedence problems.