Re:Lambdas in C
by Kototama on Friday July 01, 2011 @09:59AM
(#2718335)
Note: unlike lambdas in functional languages, this lambda does not capture the containing environment.
[ Parent
| on HN ]
That's slightly sloppy phrasing. It captures it, but it does not duplicate it, so it's lifetime is tied to the stack frame of the function you declared it in.
In short, you can only do downwards funargs.
Bah, beat me to it. It's still kind of cool though.
qsort (array, sizeof (array) / sizeof (array[0]), sizeof (array[0]),
lambda (int, (const void *a, const void *b),
{
dump ();
printf ("Comparison %d: %d and %d\n",
++ comparison, *(const int *) a, *(const int *) b);
return *(const int *) a - *(const int *) b;
}));