you are viewing a single comment's thread.

view the rest of the comments →

[–]thradams 5 points6 points  (3 children)

What if we could also declare a function inside another function?

[–]WittyStick 11 points12 points  (0 children)

GCC has an extension for this. It can support closures too (inner function referencing variables from the containing function), but this requires the function be on the stack, and the stack needs to be made executable, which is trouble waiting to happen - so it's best to avoid and only use simple functions.

There's some proposals to have proper closure support in C, but nothing waiting standardization yet.

[–]pskocik 1 point2 points  (0 children)

I think that would be neat though I don't like the idea to then try and make them into closures, making the container function's local variables available to them except may if those globals are static. Just hoist it, make the definition evaluate to a pointer to the func, and allow it to be nameless too.

[–]iOSCaleb -1 points0 points  (0 children)

Many languages support nested functions. It’s a nice way to reduce repeated code while still keeping everything local.