Nested Functions, also known as closure, belongs to the concept of functional language and has always thought that closure is not supported in C. Now it seems that I am wrong, but it is not supported in C standard, but GCC supports it.
Since GCC supports closure, lexical scoping is also supported. label in C can also be freely redirected in nested functions, and the nested function can be called externally as the return address, this is consistent with the concept in lisp.
C code
Foo (double a, double B)
{
Double square (double z) {return z * z ;}
Return square (a) + square (B );
}
Bar (int * array, int offset, int size)
{
Int access (int * array, int index)
{Return array [index + offset];}
Int I;
/*...*/
For (I = 0; I <size; I ++)
/*... */Access (array, I )/*...*/
}
Bar (int * array, int offset, int size)
{
_ Label _ failure;
Int access (int * array, int index)
{
If (index> size)
Goto failure;
Return array [index + offset];
}
Int I;
/*...*/
For (I = 0; I <size; I ++)
/*... */Access (array, I )/*...*/
/*...*/
Return 0;
/* Control comes here from access
If it detects an error .*/
Failure:
Return-1;
}
From bookjovi