Thread View: comp.std.c++
2 messages
2 total messages
Started by rwallace
Sun, 05 Aug 1990 17:40
Local functions
Author: rwallace
Date: Sun, 05 Aug 1990 17:40
Date: Sun, 05 Aug 1990 17:40
27 lines
1840 bytes
1840 bytes
Is there any chance of introducing local functions into C++? i.e. declaring a function within a block in another function so it can only be called from within that block and can access that block's local variables. This would be useful in the following situation which I've run into a few times: say you've got a large function with a section of code, repeated several times, which performs operations on variables local to the function. You want to save code space and increase maintainability by factoring out this section of code into another function. Problem: the small function can't access the big function's local variables unless you a) pass pointers to those local variables to the small function as parameters (this loses most of the benefits of factoring out the code of the small function) b) make the big function's local variables local only to the module not to the function, so the small function can access them (with the obvious problem of reduced locality of data) ... what you really want to do is declare the small function as local to the big function. I know handling the stack allocation for local functions is a severe pain for the compiler writer. Is there any loss of run-time efficiency? (If there is an unavoidable loss that can't be fixed by a clever optimizer, forget I mentioned the subject). "To summarize the summary of the summary: people are a problem" Russell Wallace, Trinity College, Dublin rwallace@vax1.tcd.ie
Re: Local functions
Author: Roland McGrath
Date: Sun, 05 Aug 1990 22:46
Date: Sun, 05 Aug 1990 22:46
6 lines
795 bytes
795 bytes
GCC version 2 (not yet released, and don't ask when) supports nested functions in C. I imagine the support is (or will be) in C++ as well. -- Roland McGrath Free Software Foundation, Inc. roland@ai.mit.edu, uunet!ai.mit.edu!roland
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads