Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!mailrus!uunet!mcsun!ukc!tcdcs!swift.cs.tcd.ie!vax1.tcd.ie!rwallace From: rwallace@vax1.tcd.ie Newsgroups: comp.std.c++ Subject: Local functions Message-ID: <6685.26bc5a13@vax1.tcd.ie> Date: 5 Aug 90 17:40:35 GMT Organization: Computer Laboratory, Trinity College Dublin Lines: 27 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