tags:

views:

104

answers:

2
  1. 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).

  2. If a function say(a()) is define with in another function say(b()) then the lifetime of a() would be whole program?

  3. Will the storage for a() ll be created in a stack allocated to function b().?

+1  A: 

1) 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.

Daniel Stutzbach
2) No, the lifetime of the inner function is restricted to the life of the outer function,yeH BUT THEN allocation of inner function shld be with in the stack of outer function so that when outer function return then whole stack frame which were allocated to outer function get destroyed and thus stack of inner function too.
fluty
@user359179: huh?
Daniel Stutzbach
hmmmmm whats wrong sir?
fluty
@user359179: there can't be stack frames allocated from the inner function when returning from the outer function, because that means the inner function hasn't returned yet, and you could only have called it from the outer function, meaning you can't return from it yet.
Claudiu
+1  A: 

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.

Joseph Quinsey
thankz all of you:)
fluty