开发者

nested function

  1. I just came 开发者_如何学JAVAacross 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().?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜