From -7869477405857392656
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,fb1a92fa405c930c
X-Google-Attributes: gidf78e5,public
From: David R Tribble <david@tribble.com>
Subject: Re: nested functions
Date: 1999/06/25
Message-ID: <3772A736.559EB26B@tribble.com>#1/1
X-Deja-AN: 493666202
Content-Transfer-Encoding: 7bit
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> <unw93.3328$uk.51917@newscene.newscene.com>
X-Original-Date: Thu, 24 Jun 1999 16:46:30 -0500
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: news@news.unimelb.edu.au
X-Trace: izvestia.its.unimelb.edu.au 930291820 11659 128.250.29.16 (25 Jun 1999 06:23:40 GMT)
Organization: The Vast Right-Wing Conspiracy
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUAN3MgS+EDnX0m9pzZAQEqhQF/d5Ql6KtgzOUR0DZUeR+OmaZD2vuBT96V bxngNAhgMsV8RwUpEho31JKoctKAJYqS =C06F
Mime-Version: 1.0
NNTP-Posting-Date: 25 Jun 1999 06:23:40 GMT
Newsgroups: comp.std.c++

John Potter wrote:
> 
> David R Tribble <dtribble@technologist.com> wrote:
>: I disagree; I don't think it makes much sense to call or pass a
>: pointer to a local function to functions outside its scope (i.e,
>: outside its enclosing function).  It's analogous to passing pointers
>: to local structures to other functions outside the function 
>: containing the structure declaration.
> 
> Disallow passing address of a local int too?  A structure is a
> complete type a function is just a prototype.  Pointer to function
> with a given prototype does not need the name.  A structure is a
> type and has a name.  Two structure types with the same layout
> have different types.  Two functions with the same prototype have
> the same pointer type.

Passing a pointer to a local int to another function requires the
second function to use the well-defined type 'int*'.  Passing a
pointer to a locally defined struct type requires the second function
to use a parm of type - what?  If the local struct is not a derived
type, then it is a completely unique type which is unknown outside of
its parent function (which can't be forward-declared).

A pointer to a local function is not the same as a pointer to a
nonmember function, because it entails context information (at the
very least, the compiler needs to know how many levels it has in its
display frame).  This is analogous to a pointer to a locally defined
struct, i.e., like saying that a pointer to a local function is a
completely unique type which is unknown outside of its parent
function.

Supposedly, this difference is solved using pointers to trampolines
as pointers to local functions.  But I'm not convinced that
trampolines can be implemented in all C++ implementations.

>: P.S.  I personally don't see any need for nested functions. Still,
>: they make for an interesting discussion in language design.
> 
> Me either.  Real nested functions have been around a long time in
> several languages.  I don't think that your watered down versions
> will provide anything of interest.  They could not be used as
> call-backs with context which was the original poster's desire.

At this point, I'm not sure fully-unwatered versions of local
functions will provide much of interest either.

-- David R. Tribble, dtribble@technologist.com --
---
[ 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              ]



