Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
inner function closure in C
#include <stdlib.h>
#include <stdio.h>
int(*outer(int val))() {
int inner() {
return val;
}
return inner;
}
int main() {
printf("%d\n", outer(5)());
return 0;
}
$ gcc -fnested-functions -o closure closure.c
$ ./closure
5
@mattyoho
Owner

But I can't help thinking inner had been freed before it was called and I got lucky...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.