📰 IT NachrichtenToday’s NYT Mini Crossword Answers for Saturay, Sept. 12(12.09.2026 um 07:43 Uhr)
🔧 AI Nachrichten Etzioni on AI: What kids tell chatbots, but not you(04.09.2026 um 16:05 Uhr)
🔧 AI Nachrichten OpenAI Wants to Know if an AI Industry Slowdown Would Even Be Legal(11.09.2026 um 01:28 Uhr)
🔧 AI Nachrichten OpenAI puts Pro subscriptions on hold due to Astra demand(10.09.2026 um 22:59 Uhr)
🔧 AI Nachrichten OpenAI’s feud with mathematicians is only escalating(11.09.2026 um 22:57 Uhr)
📰 IT NachrichtenToday’s NYT Mini Crossword Answers for Saturay, Sept. 12(12.09.2026 um 07:43 Uhr)
🔧 AI Nachrichten Etzioni on AI: What kids tell chatbots, but not you(04.09.2026 um 16:05 Uhr)
🔧 AI Nachrichten OpenAI Wants to Know if an AI Industry Slowdown Would Even Be Legal(11.09.2026 um 01:28 Uhr)
🔧 AI Nachrichten OpenAI puts Pro subscriptions on hold due to Astra demand(10.09.2026 um 22:59 Uhr)
🔧 AI Nachrichten OpenAI’s feud with mathematicians is only escalating(11.09.2026 um 22:57 Uhr)

🔧 Programmierung 🕛 vor 6 Monaten 6 Min Lesezeit
0

The Inline Myth: Why the inline Keyword is Just a Suggestion

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

Inline functions are functions that the compiler may expand directly at the place where they are called, instead of performing a normal function call.



Inline functions are often misunderstood especially by beginners who assume that writing the inline keyword forces the compiler to inline a function.



In reality, inline is only a suggestion and modern compilers are far smarter than we realize.



This post explains:




  • What inline actually means

  • Why it is only a hint

  • Inline vs macros

  • How modern compilers decide to inline

  • Performance and binary size trade-offs

  • Real compiler behavior using assembly output






Inline Is a Suggestion, Not a Command



When you write:




CODE
inline int add(int a,int b){
return a + b;
}






you are not instructing the compiler to inline this function.



You are merely suggesting that inlining may be beneficial.



The compiler is completely free to:




  • Inline the function

  • Ignore the suggestion

  • Inline it in some call sites but not others






Why?



Because the C/C++ standards do not require compilers to perform any optimization at all.



Inlining is an optimization, and therefore it cannot be mandatory.



If inline were a mandatory, optimization itself would no longer be optional and this would violate the language standard.






Modern Compilers Inline Even Without inline



A very common misconception is:




If I don’t write inline, the function won’t be inlined.




This is false.



Modern compilers (GCC, Clang, MSVC):




  • Perform automatic inlining

  • Analyze function size, call frequency, and context

  • Inline functions even if the inline keyword is not used



Example:




CODE
int add(int a,int b){
return a + b;
}
int main(){
return add(2,3);
}






With optimizations enabled (-O2, -O3), the compiler will very likely inline such a small function.



Today, inline is more of a semantic hint than a performance switch.






Why Inline Exists at All



Inlining was originally introduced to:




  • Reduce function call overhead

  • Improve performance in tight loops

  • Replace unsafe macros



A traditional function call involves:




  • Pushing arguments onto the stack

  • Saving registers

  • Jumping to another memory location

  • Returning back



Inlining eliminates this overhead by expanding the function body at the call site.






But Call Overhead Isn’t That Expensive Anymore



Modern CPUs are highly optimized for function calls through:




  • Branch prediction

  • Instruction pipelining

  • Speculative execution



As a result, the overhead of a well-predicted function call is often very small.



In many cases, aggressive inlining does not yield significant performance gains and can even hurt performance due to:




  • Increased code size

  • Instruction cache pressure

  • Register pressure



Today, the primary benefit of inlining is not eliminating the call itself, but enabling further compiler optimizations.






How Compilers Decide to Inline



Compilers use heuristics. They compare:




  • Cost of the function call

  • Size of the function body



If the cost of call > cost of expanded code then the compiler may inline.






Likely to Be Inlined




  • Very small functions

  • Simple calculations

  • Getters/setters

  • Functions called inside loops






Unlikely to Be Inlined




  • Large functions

  • Functions with loops

  • Functions with static variables

  • Functions called via function pointers

  • Recursive functions






Recursive Functions Cannot Be Inlined



Inlining requires the compiler to expand the function body.



For recursion:




CODE
int fact(int n){
return n == 0 ? 1 : n * fact(n -1);
}






Inlining would require:




  • Infinite expansion

  • Unlimited code generation



This is impossible, so recursive functions cannot be inlined.






Inline vs Macros



Macros were the original “inline mechanism,” but they come with serious problems.






Macro Example






CODE
#define ADD(a, b) a + b






Usage:




CODE
4 * ADD(2 + 2)






Expansion:




CODE
4 * 2 + 2  //  Wrong result









Inline Function Equivalent






CODE
inline int add(int a,int b) {return a + b;
}






Usage:




CODE
4 * add(2 + 2) //  Correct









Too Much Inline Increases Binary Size



Inlining duplicates code at every call site.



If a function is used in many places:




  • Binary size increases

  • Instruction cache pressure increases

  • Performance may actually degrade



This phenomenon is known as code bloat.



So:




Inlining trades space for speed.







Experiment: Verifying Inlining Across Optimization Levels



We test a simple program with and without the inline keyword to observe how the compiler behaves at different optimization levels.



Test Code




CODE
inline int add(int a, int b) {
return a + b;
}

int main() {
return add(2, 3);
}










Case 1: Compilation with -O0 (No Optimization)






CODE
gcc -S  test.c -O0









  • No call _add

  • Function is fully inlined

  • Constant folding reduces add(2,3) to 5






Symbol Table






CODE
nm a.exe | grep add









CODE
00401b10 T ____w64_mingwthr_add_key_dtor
00403850 T ___mingw_readdir
00401460 T _add






⚠️ Important Observation

_add still exists, but it is never called.





Why _add Exists but Is Never Called



This is the core question, and the answer is subtle but fundamental.



Reason 1: External Linkage




CODE
inline int add(int a,int b);






Functions have external linkage by default, meaning another translation unit might call add().

The compiler must therefore keep the symbol.



Reason 2: No Whole-Program Visibility



Without Link Time Optimization (LTO), the compiler cannot prove the function is unused globally.





Forcing Removal of _add



Option 1: Make the Function static




CODE
static int add(int a,int b){
return a + b;
}






Internal linkage allows the compiler to remove the symbol.



Option 2: Enable Link Time Optimization (LTO)




CODE
gcc -O2 -flto test.c









⚠️ Important Note



Although the example uses the inline keyword for explanation, I also tested the same code without inline.



When compiled with -O2, the compiler still inlined the function automatically.



This confirms that inlining at higher optimization levels is driven by the compiler’s heuristics, not by the presence of the inline keyword.






Key Takeaways





  • inline is a hint, not a guarantee

  • The compiler may inline even without inline

  • Inline exists for performance optimization

  • Macros are unsafe; inline functions are type-safe

  • Recursive functions cannot be inlined

  • Excessive inlining increases binary size

  • Modern CPUs reduce the benefit of aggressive inlining

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
2 Quellen
Seattle Times sues Microsoft and OpenAI, alleging they trained their AI on its journalism
1 Quelle
Today’s NYT Mini Crossword Answers for Saturay, Sept. 12
1 Quelle
Etzioni on AI: What kids tell chatbots, but not you
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten The Inline Myth: Why the inline Keyword is Just a Suggestion

Thematisch verwandte Begriffe: Inline, Myth, inline, Keyword · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...