Lambdas, Nested Functions, and Blocks
13 days ago
- #Lambda Functions
- #Compiler Extensions
- #C Programming
- The article discusses the need for lambdas in the C programming language, highlighting various existing solutions like GCC's Nested Functions, Clang's Blocks, and Jens Gustedt's proposal for Lambdas.
- GCC's Nested Functions allow defining functions within functions but have security issues like executable stacks, leading to their ban in many contexts.
- Clang's Blocks provide a safer alternative to GCC's Nested Functions by avoiding executable stacks but introduce complexities like mandatory heap allocation in some cases and lack of direct conversion to function pointers.
- Jens Gustedt's proposal for Lambdas in C introduces explicit captures and avoids many pitfalls of Nested Functions and Blocks, offering more control and safety.
- The article emphasizes the importance of developer control over language features, criticizing implicit magic and advocating for predictable, tractable rules in language standards.
- Security concerns, ABI stability, and multithreading issues are discussed as significant challenges with current implementations of function+data types in C.
- The proposal for Lambdas is presented as a solution that balances safety, control, and usability, drawing from lessons learned from existing implementations.