I just came across that ANSI(ISO) ain't allowing nesting of function.. i want to know what makes gnu c ito implement this functionality(why such need arise).
If a function say(a()) is define with in another function say(b()) then the lifetime of a() would be whole program?
Will the storage for a() ll be created in a stack allocated to function b().?
views:
104answers:
21) Highly subjective. Not a clue. :-)
2) No, the lifetime of the inner function is restricted to the life of the outer function. See the GCC documentation on nested functions. If you retain a pointer to the inner function and call it after the outer function returns, Bad Things may happen.
3) The inner function allocates its own stack space, just like any other function. It has to allocate its own space in order to support recursive calls.
I believe http://en.wikipedia.org/wiki/Nested_function answers most of your question #1. Question #2 is addressed in more detail in http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html, and question #3 in http://gcc.gnu.org/onlinedocs/gccint/Trampolines.html.
Edit: (Aside) The wikipedia article inexplicably left PL/M off its list of ALGOL-based languages which support nested functions. Ah, the good old days.