Containers, Templates, Lambda Expressions in C

Not many people know this, but the C language (with the help of gcc extensions) can support templates and lambda expressions.

I know I’m going to get emails / comments about how I butchered the C language. So let me start out with a word of caution, this is for educational use only, and is not intended to be used in production code.

We start off with a little known gcc extension that allows functions to be declared inside of functions. These functions are normally only accessible from inside the scope in which it was declared.

void parent() {
int child() {
return 42;
}
printf("%d\n", child());
}

Theres also a gcc extension that allows you to nest instructions inside of scope operators, where the instructions are evaluated and returned.

If we were to combine these two examples we can have a scope operator return a function pointer to a nested function. The result would look very similar to a lambda expression, but in C! FYI: You can use the dollar sign as a symbol name.