3 ms·
if your outer function f called a function 'quicksort' which called a function 'partition' which called your nested function 'compare', how did 'compare' get ac
by kragen 3y ago
if your outer function f called a function 'quicksort' which called a function 'partition' which called your nested function 'compare', how did 'compare' get access to the variables of f from its statically enclosing scope? how did it know how many locals 'quicksort' and 'partition' had pushed onto the operand stack?
- loup-vaillant 3y agoErr… I think recursive inner functions would just blow up… oops. I guess it’s a good thing I didn’t advertise inner functions and only used them in the standard library…
- kragen 3y agowell, that's the problem the static link solves; it's not such a difficult thing to implement if you let procedure values (function pointers) be two words instead of one. gcc emits trampoline code onto the stack at runtime to support this without breaking abi compatibility, so the pointer to the nested function actually points to the trampoline, which just supplies the static link and calls the real nested function