From -6702493297776599026
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,fb1a92fa405c930c
X-Google-Attributes: gidf78e5,public
From: jpotter@falcon.lhup.edu (John Potter)
Subject: Re: nested functions
Date: 1999/06/16
Message-ID: <wkP93.15214$uk.221592@newscene.newscene.com>#1/1
X-Deja-AN: 490291155
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
References: <7jd4c5$nup$1@nnrp1.deja.com> <7jjjr6$r02$1@nnrp1.deja.com> <7jma5c$i85@abyss.West.Sun.COM> <FD38vK.CC4@research.att.com> <7jrpss$ogk$1@nnrp1.deja.com> <FqA83.38464$wk2.553149@newscene.newscene.com> <37659D89.565ACF7D@technologist.com> <7k5ncv$n8u$1@nnrp1.deja.com> <376690B6.6231FB13@technologist.com>
X-Original-Date: 16 Jun 1999 10:25:06 -0500
X-Complaints-To: news@news.unimelb.edu.au
X-Trace: izvestia.its.unimelb.edu.au 929547171 18610 128.250.29.16 (16 Jun 1999 15:32:50 GMT)
Organization: Newscene Public Access Usenet News Service (http://www.newscene.com/)
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUAN2fDg+EDnX0m9pzZAQEVBwF/f+Vr1z+8fglopHz2I+RsWC1WWXsk+uAA r1kakEFiCKWLKhyzfaDHWjLUCZ2x4vDv =Rc18
NNTP-Posting-Date: 16 Jun 1999 15:32:50 GMT
Newsgroups: comp.std.c++

David R Tribble <dtribble@technologist.com> wrote:

: No one's addressed the problem of what happens when a local function
: is invoked through a pointer after its outer function's scope has
: ended.  Is this simply undefined behavior?  Is an exception thrown?

No problem.  If the function accesses its outer function's context
that is undefined behavior just like returning a reference to local
context.  Exceptions?  Since it is undefined behavior, anything could
happen :)

: My restriction avoids this whole problem.

By making local functions useless.  Baby and bathwater?

: It also makes the implementation of local function pointers much
: simpler

No, it complicates the issue by creating an unneeded new type.  A
local function pointer is just a function pointer.  See below.

: My guess is that nested functions would be no more harder to
: implement than exception handling.

Good point.  Likely easier, lots of history to use.

: Oh, and by the way, how do nested functions complicate exception
: handling?  No one's discussed that either.

They are just functions, no change.

: A nested function requires a slightly more complex invocation frame,
: called a "display" (see chap.7 of the Red Dragon compiler book),
: which allows it to access its outer function's local variables (to
: any arbitrary nesting level) in addition to its own local variables.

Now the clincher.  Normal functions are nested to level zero.  They
have access to the global context as well as their own.  All
functions are nested functions.

Now you have the context.  Is the cost of the display for all
functions justified by the gains of the feature?  There have been
statements that the cost can be reduced to almost nothing and
possibly nothing when not used.

There are likely some unasked and/or unanswered questions, but the
type of pointer to local function is not one of them for anyone
else.  Those who want them have uses for them and normal function
pointers are a requirement for those uses.

John
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



