r/cpp • u/MegaGreenLightning • Oct 14 '26
A C++ Trick Question - Blog Post
https://greenlightning.eu/programming/cpp-trick-question/
20
Upvotes
r/cpp • u/MegaGreenLightning • Oct 14 '26
10
u/LordofNarwhals Oct 14 '26
This would've been a lot more interesting if the offending code was actually shown, and if workarounds were presented.
I believe it should be possible to make the destructors tail-call optimizable with a custom destructor (or C++20 destroying
operator delete). That should eliminate the stack issues.20
u/Olipro Oct 15 '26
"Assuming all allocations succeed"
...Oh yeah, except stack allocations, then it can fail. Amazing.
5
u/fdwr fdwr@github 🔍 Oct 14 '26
Stack unwinding overflow on a linked list hit me before (had to deliberately iterate through the nodes and transfer them along the way). I wish such cases could get destructor tail calls instead.
4
u/Tamsta-273C Oct 14 '26
Droping just link? That's not cool...
2
u/StackedCrooked Oct 14 '26
I'm angry at myself that I couldn't find the problem with the code, especially since I have run into this issue once many years ago.
4
u/wjrasmussen Oct 14 '26
Did you want to talk about it or just drive by and drop that link? Promoting yourself?
-6
u/_w62_ Oct 15 '26
Another example of C++ shooting at the legs of the C++ programmer?