473,324 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Re: Return of nested function

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
2 1638
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Andy Baker | last post by:
Hi there, I'm learning Python at the moment and trying to grok the thinking behind it's scoping and nesting rules. I was googling for nested functions and found this Guido quote:...
5
by: Andrew Poulos | last post by:
If I'm searching for an occurance of a value in a multi-dimensional array how can I get it's index returned as an array, if found? For example, if: foo = new Array(); foo = , 5, , 9, 10]; ...
5
by: Agnes | last post by:
Can combo box return more that 1 item ?? for my currency combo box, short_code, descripiton, currency rate. as user choose the description, I need to get both short_code & currency rate result. ...
1
by: moondaddy | last post by:
I need to return a nested string array from a function and am getting hung up on syntax. Here's a simple example of a function that returns the array and how I'm trying to call it. Private Sub...
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
14
by: Alexander Stoyakin | last post by:
Hello! Please advise on the following issue. I have a function which returns 1 or 0 in multiple branches, and it must perform the same code before each return, like this: int fun() { if (some...
4
by: Wolfgang Draxinger | last post by:
If you know languages like Python or D you know, that nested functions can be really handy. Though some compilers (looking at GCC) provide the extension of nested functions, I wonder, how one...
11
by: =?Utf-8?B?Um9nZXIgVHJhbmNoZXo=?= | last post by:
Hello, I have a question about the infamous GOTO statement and the way to return a result from a sub: I have a sub that has to make some calls to external COM methods, and because these...
4
by: barcaroller | last post by:
I am trying to adopt a model for calling functions and checking their return values. I'm following Scott Meyer's recommendation of not over-using exceptions because of their potential overhead. ...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.