Tail-call optimization in C is relatively recent (2025)
prakashqwerty
88 points
60 comments
August 10, 2026
Related Discussions
Found 5 related stories in 55.0ms across 4,128 title embeddings via pgvector HNSW
- Using GCC's Nested Functions with Wide Pointers and No Trampolines II uecker · 92 pts · August 15, 2026 · 49% similar
- Co-Opting Linux Processes for High-Performance Network Simulation (2022) teleforce · 19 pts · July 24, 2026 · 45% similar
- Optimizing things in the USSR (2016) cassepipe · 44 pts · August 20, 2026 · 45% similar
- Tumble Forth – from assembly to OS with C compiler (2023) vicek22 · 70 pts · August 21, 2026 · 43% similar
- Zig's Incremental Compilation Internals garyhtou · 218 pts · July 28, 2026 · 42% similar
Discussion Highlights (8 comments)
mmsc
and TCO was added then removed from js! https://stackoverflow.com/a/54721813 This leads to fun stack-overflow bugs too in a lot of js code (one solution is to flatten: https://joshua.hu/javascript-infinite-tail-call-recursion-st... )
kenjin4096
I think Anton is replying to me in that LWN article IIRC. I personally didn't know C only had tail calls that late and learnt something new there! On the other hand, I am pretty new to the compiler space myself, and I count early 2000s as a pretty long time ago, though again it is not that far back considering how long other language implementations had tail calls like in ML or variants since 1980-90s.
messe
> In 2001 Mark Probst implemented tail-call optimization in GCC with a separate calling convention; he lists the limitations of the then-existing tail-call optimization in GCC in section 6.4, among them: "It cannot handle indirect calls" (which would have been used in tail calls for interpreter dispatch). Relatively recent being a quarter of century? Or at least a fifth of a century for indirect calls[1] (GCC 3.4.6 is the earliest I see on Compiler Explorer, released March 2006). [1]: https://godbolt.org/z/vvcnn54oM
nyeah
>That quote is the article, and it's a little surprising that it's buried so far into the content Is it really surprising in 2026? Today's online writing style is not primarily designed to communicate. It's designed to keep the reader 'engaged' for as long as possible. The reader's time is a resource to be extracted. I'm absolutely not poking this author individually. It's the writing style of the net.
swiftcoder
> In 2001 Mark Probst implemented tail-call optimization in GCC MSVC didn't add tail-call optimisation until sometime in the 2010s, IIRC. I distinctly remember sending a tail-recursive C++ program to someone who developed on Windows, and it crashing, in the late mid-to-late 2000s.
hnfvovpje4
Clear, useful, done
drdexebtjl
Unless the language can guarantee TCO, I don’t feel comfortable writing tail recursive code and being at the compiler’s/interpreter’s mercy. I think the framing of TCO as an optimization has been very unfortunate.
torginus
What practical patterns are enabled by TCO in C? My impression is that every tail call can written as a loop much more naturally. Tail calls are important in functional languages where you don't have mutable loop variables. And imo they are an ugly hack even there - one of the few core constructs where its readily apparent you're not programming an abstract machine but a real, and limited computer. For example the most natural way to write factorial: let rec factorial n = if n <= 1 then 1 else n * factorial (n - 1) is not tail recursive, and will overflow if the compiler fails to optimize.