#include #include /* type des fonction N -> N */ typedef int (*nat2nat) (int); /* quelques fonctions N -> N */ int triple(int x) { return 3*x; } int successeur(int x) { return x + 1; } /* fonction passee en parametre OK */ int appliquera2(nat2nat f) { return f(2); } /* fonction comme valeur de retour: FAIL */ nat2nat ajouteur(int n) { /* s'il y avait des clotures n serait alloue sur le tas et non (seulement) sur la pile pour survivre a l'invalidation du cadre courant */ int f(int x) { return x + n; } return f; } void garbage() { int t[1024]; int i; for (i = 0; i < 1024; i += 1) { t[i] = 0; } } int main() { nat2nat f; f = ajouteur(100); garbage(); /* ecrase les anciens cadres sur la pile */ printf("%d\n", f(2)); return EXIT_SUCCESS; }