Comments on: Nested functions in GCC http://www.weaselhat.com/2010/03/03/nested-functions-in-gcc/ Mon, 15 Mar 2010 20:38:48 +0000 hourly 1 https://wordpress.org/?v=6.3.2 By: Zjzzzjz http://www.weaselhat.com/2010/03/03/nested-functions-in-gcc/comment-page-1/#comment-497 Mon, 15 Mar 2010 20:38:48 +0000 http://www.weaselhat.com/?p=208#comment-497 Is your laptop on Mac? If so, this might be the reason… Because I think nested-function is only working with Mac now, it basically comes from ‘block function’ in ObjectC.

I just wanted to know how the local variables in the closure are stored. From your code, every time f is called, a fresh function pointer to that nested function is returned, where the local variables on f’s stack must be stored some where. I guess they must be on heap. But how is this memory space on heap released? since there is no GC in GCC, if we call f’ zillions of times, will it use all of the memory space…?

]]>
By: Michael Greenberg http://www.weaselhat.com/2010/03/03/nested-functions-in-gcc/comment-page-1/#comment-496 Mon, 15 Mar 2010 20:15:32 +0000 http://www.weaselhat.com/?p=208#comment-496 In reply to Zjzzzjz.

I was using my laptop’s OS X build of gcc. It doesn’t work on any of the CETS machines for me, either.

]]>
By: Zjzzzjz http://www.weaselhat.com/2010/03/03/nested-functions-in-gcc/comment-page-1/#comment-495 Mon, 15 Mar 2010 19:28:07 +0000 http://www.weaselhat.com/?p=208#comment-495 How did you get it compiled in that day? My Eniac GCC does not like this option -fnested-function or -fnested-functions:

cc1: error: unrecognized command line option “-fnested-function”
cc1: error: unrecognized command line option “-fnested-functions”

]]>
By: Michael Greenberg http://www.weaselhat.com/2010/03/03/nested-functions-in-gcc/comment-page-1/#comment-492 Wed, 03 Mar 2010 22:38:30 +0000 http://www.weaselhat.com/?p=208#comment-492 In reply to Ben Karel.

Hadn’t had a look at the manual (figures, doesn’t it?), so I suppose all of these behaviors are out of spec anyway. What troubles me about this is the existence of weird out of spec behaviors that are sometimes correct. That, I suppose, is where your “but it’s C” comment comes in. Point taken. :)

]]>
By: Ben Karel http://www.weaselhat.com/2010/03/03/nested-functions-in-gcc/comment-page-1/#comment-491 Wed, 03 Mar 2010 22:31:02 +0000 http://www.weaselhat.com/?p=208#comment-491 But it’s C; the compiler isn’t going to do any transformations like closure- or assignment conversion that could violate the transparency of the cost model. The compilation model is simple: a nested function is a function pointer with access to the frame pointer of its lexical parent function.

And the manual does explicitly say “If you try to call the nested function through its address after the containing function has exited, all hell will break loose.” ;-)

]]>