2 ms·
If they decided to hand out flying ponies… • blocks are pretty spiffy. • nested functions, by which I mean I don't need access to the parent's variables, I ju
by jws 11y ago
If they decided to hand out flying ponies…
• blocks are pretty spiffy.
• nested functions, by which I mean I don't need access to the parent's variables, I just want to tuck this little function inside the namespace of my existing function because darn it, it's two lines long and I can give it a tiny name, and I don't have to stick it above my giant function comment header where I can't see it while I'm in the code that is using it. I just want to abstract these two lines that I need to do three times in this function. gcc has these, clang thinks it's hard in their world.
- david-given 11y agogcc 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.