Isn’t this just a normal compiler extension though?
Conversation
It is. it’s enabled by default in gcc, which I think makes it relevant. It has terrifying codegen, and clang thankfully refuses to support it.
In 2021, gcc will make the stack executable and execute code there if you use it. There’s a warning — not on by default. (-Wtrampolines)
1
2
I seem to recall that those were implemented by RMS in one of his weird "let's import Lisp conventions regardless of whether they make sense" moments, right?
2
2
They were implemented by rms, they are a glorious language extension, now embraced by both swift and c#
1
The feature is nice! The implementation in gcc is dangerous.
2
2
It's a closure unable to live past the block where it's declared and depending on hacks to make it backwards compatible with function pointers.
The concept might have been nice, but they just went with a quick hack instead of designing a serious feature. It was always a hack.
1
3
Smalltalk, Objective-C, Eiffel, etc. predate GCC nested functions.
en.wikipedia.org/wiki/Eiffel_(p
Could have added some syntax for a special function pointer type with a data pointer for captures and it would still be useful today. Probably widely used, and perhaps standardized.
2
1
Clang already did this: en.wikipedia.org/wiki/Blocks_(C. I think there was some effort to get it into the standard at some point, but I don’t know what happened to that.
2
1
It's definitely a nice implementation of it. I think it's an obvious design and I'm not sure why GCC didn't end up with something similar ages ago. I think they just didn't try to design a serious feature.
Never seen blocks used outside of Objective-C for macOS / iOS though.
1
1
Only around for about 3 years before Swift was on the scene. Also, coincides with C++11 lambdas becoming available, which are portable, although they try to avoid type erasure / dynamic dispatch since it's C++. I think C++11 lambdas were available first in Clang.
1
1
I only actually truly learned C++ around 2009/2010 rather than just C and both GCC/Clang had lambdas via -std=c++0x already. Blocks seem to be from 2011 and then Swift was 2014. Overshadowed by other things, but it's very a nice feature which should have existed 30 years earlier.



