By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,537 Members | 2,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,537 IT Pros & Developers. It's quick & easy.

Re: Return of nested function

P: n/a
Nick Keighley schrieb:
>- I use GCC (and its extension for the nested functions)

ah. As you note this is a gcc extension. You need to ask on
a gcc group for the exact semantics of their nested functions
Why is there actually a *need* for nested functions? If functionality of
subfunctions which are only locally visible is desired, why not put the
nesting function parent and its nested children all in one module,
declare the children static - voila. Std-C.

Regards,
Johannes

--
"Wer etwas kritisiert muss es noch lange nicht selber besser können. Es
reicht zu wissen, daß andere es besser können und andere es auch
besser machen um einen Vergleich zu bringen." - Wolfgang Gerber
in de.sci.electronics <47***********************@news.freenet.de>
Jul 15 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Johannes Bauer wrote:
Nick Keighley schrieb:
>>- I use GCC (and its extension for the nested functions)

ah. As you note this is a gcc extension. You need to ask on
a gcc group for the exact semantics of their nested functions

Why is there actually a *need* for nested functions? If functionality of
subfunctions which are only locally visible is desired, why not put the
nesting function parent and its nested children all in one module,
declare the children static - voila. Std-C.
It's possible (even likely) that the GCC semantics is more powerful
than this would allow. For example, it might implement Pascal-style
nesting, where functions can refer to the locals of the functions
they are nested in while those functions are still executing.

/Clearly/ you can fabricate code to get round this, unless (as
you likely will) you have to pass your function-plus-fabrications
through a function-pointer-sized-and-typed slot. Oops.

--
If you read the signature, the signature reads you. - eh

Hewlett-Packard Limited Cain Road, Bracknell, registered
no:
registered office: Berks RG12 1HN 690597
England

Jul 15 '08 #2

P: n/a
In article <30************@joeserver.homelan.net>,
Johannes Bauer <df***********@gmx.dewrote:
>Why is there actually a *need* for nested functions? If functionality of
subfunctions which are only locally visible is desired, why not put the
nesting function parent and its nested children all in one module,
declare the children static - voila. Std-C.
Is there actually a *need* for local variables? If functionality of
variables which are only locally visible is desired, why not put the
function in a file by itself and declare the variables static at file
scope - voila.

The point, of course, is that nested functions can do more than
control the visibility of the function name. They let you create
closures - instances of functions that are "closed" over the bindings
of variables in enclosing scopes.

[Yes, you could have an implementation of nested functions that didn't
provide this, just as you could have an implementation of local
variables that didn't make recursive calls work. Then they really
wouldn't be much use.]

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Jul 15 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.