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.

CategoryFunction-related
KindKeyword / Statement
C standardC99

📝 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 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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏