Skip to content

Instantly share code, notes, and snippets.

@mooz
Created March 12, 2010 14:01
Show Gist options
  • Save mooz/330323 to your computer and use it in GitHub Desktop.
Save mooz/330323 to your computer and use it in GitHub Desktop.
#include <stdio.h>
void dotimes(void (*func)(void), int n)
{
int i;
for (i = 0; i < n; ++i)
{
func();
}
}
int main()
{
int level = 0;
void level_upper() { level++; }
printf("%d\n", level);
dotimes(level_upper, 10);
printf("%d\n", level);
dotimes(level_upper, 5);
printf("%d\n", level);
return 0;
}
/*
* masa@zola:$ ./closure.out
* 0
* 10
* 15
* masa@zola:$
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment