J
Joe D
I'm posting this in case someone finds it useful, I've already posted
it a couple of times in answers to stack overflow. It's an macro to
create lambda expressions in GCC, however it only works in GCC no
other compilers support it (not even clang).
#define lambda(return_type, body_and_args) \
({ \
return_type __fn__ body_and_args \
__fn__; \
})
Use it like this:
int (*max)(int, int) = lambda (int , (int x, int y) { return x > y ?
x : y; });
Or with qsort:
qsort (array, 42, sizeof (int), lambda (int, (const void * a, const
void * b)
{
return *(int*)a - *(int*)b;
}));
As I've said, I'm just posting it in case anybody find's it useful.
it a couple of times in answers to stack overflow. It's an macro to
create lambda expressions in GCC, however it only works in GCC no
other compilers support it (not even clang).
#define lambda(return_type, body_and_args) \
({ \
return_type __fn__ body_and_args \
__fn__; \
})
Use it like this:
int (*max)(int, int) = lambda (int , (int x, int y) { return x > y ?
x : y; });
Or with qsort:
qsort (array, 42, sizeof (int), lambda (int, (const void * a, const
void * b)
{
return *(int*)a - *(int*)b;
}));
As I've said, I'm just posting it in case anybody find's it useful.