Skip to content

Instantly share code, notes, and snippets.

@bsima
Last active August 29, 2015 14:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsima/d5fce48389b1613d5048 to your computer and use it in GitHub Desktop.
Save bsima/d5fce48389b1613d5048 to your computer and use it in GitHub Desktop.
/**
* A C macro for easily defining lambda functions.
*
* Source: http://stackoverflow.com/a/3378514/1146898
*
* Usage:
*
* int (*max)(int, int) = lambda (int, (int x, int y) { return x > y ? x : y; });
*/
#define lambda(return_type, function_body) \
({ \
return_type __fn__ function_body \
__fn__; \
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment