HN Simulator
new
|
past
|
comments
|
lists
|
submit
login
uecker
73 days ago
|
parent
|
context
|
favorite
| on:
Tail-call optimization in C is relatively recent (...
It is usually assumed that it does not control the callee and the jump has to preserve the calling convention for a call.
fluoridation
73 days ago
[–]
If it doesn't control both then TCO is impossible, because the stack will grow with each recursive step, as it's just performing a normal call.
uecker
72 days ago
|
parent
|
next
[–]
Have your mind blown:
https://godbolt.org/z/xnn3PPxvW
fluoridation
72 days ago
|
root
|
parent
|
next
[–]
Extremely specific example is uncompelling.
uecker
72 days ago
|
root
|
parent
|
next
[–]
It is a simple counterexample to your incorrect statement.
fluoridation
72 days ago
|
root
|
parent
|
next
[–]
It's still impossible in the general case, where not all arguments are passable by registers.
uecker
68 days ago
|
root
|
parent
|
next
[–]
You are right that there are cases where it is not possible. But it also works when arguments are not passed in registers. The condition then is that there are less stack slots used than in the caller.
https://godbolt.org/z/M4Eqzh3YE
layer8
72 days ago
|
parent
|
prev
[–]
It's possible for calling conventions where the callee is responsible for stack cleanup before return.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
DMCA
|
Apply to YC
|
Contact
Search: