3 ms·
gcc nested functions do have access to their parent's variables. Obviously only until the parent exits --- they're not closures. I would love for this to be in
by david-given 11y ago
gcc nested functions do have access to their parent's variables. Obviously only until the parent exits --- they're not closures.
I would love for this to be in the standard, particularly if they come up with a nested function literal syntax. Having them would make things like mutation callbacks and foreach() so much cleaner.
- tveita 11y agoNested functions are convenient, but when you take the address of a nested function that refers to surrounding variables, GCC puts a small trampoline function on the stack. To do this it has to disable the no-execute flag on the stack, which makes it significantly easier to exploit stack overflow vulnerabilities in your program. Since the implementation is somewhat complex and system-specific, depends on memory that is both writeable and executable, and requires disabling security features on modern OSes, I doubt GCC style nested functions will make it into the standard.