From 7232814254209777148
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,fb1a92fa405c930c
X-Google-Attributes: gidf78e5,public
From: clamage@eng.sun.com (Steve Clamage)
Subject: Re: nested functions
Date: 1999/06/09
Message-ID: <7jmdcv$a56$1@engnews1.eng.sun.com>#1/1
X-Deja-AN: 487610839
X-NNTP-Posting-Host: taumet.eng.sun.com
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <7jd4c5$nup$1@nnrp1.deja.com> <7jjjr6$r02$1@nnrp1.deja.com> <7jma5c$i85@abyss.West.Sun.COM>
X-UID: 0000000001
X-Status: $$$T
Organization: Sun Microsystems Inc., Mountain View, CA
Newsgroups: comp.std.c++
Originator: clamage@taumet


stanley@west.sun.com (Stanley Friesen [Contractor]) writes:

>In article <7jjjr6$r02$1@nnrp1.deja.com>,  <wmm@fastdial.net> wrote:
>>In article <7jd4c5$nup$1@nnrp1.deja.com>,
>>1) Runtime overhead.  The function calling sequence has to be
>>modified to maintain a display pointer or the like. ...

>Why do local functions have to have the same calling sequence as non-local
>functions?  Given the C++ requirement for all functions to be declared
>prior to a call, the compiler can always tell if a call is to a namespace
>scope funcion or to a local one.

Consider function pointers:

extern int f(int);
extern int(fp*)(int);

void g1()
{
    int h(int) { ... } // supposing C++ had local functions
    fp = h;
}

void g2()
{
    fp = f;
}

int main()
{
    if( ... )
	g1(); // sets fp to local function
    else
	g2(); // sets fp to global function

    fp(3);
}

If the calling sequences for g1::h and f are not the same,
the code can't work. Either you need a different kind of
function pointer for local functions, or you extend the
calling sequence of global functions to match that of local
functions.

A possible approach, as Mike Miller suggested, is to give C++
functions the extended calling sequence so that C compatibility
would be maintained. A local function could not have C linkage.

Another approach, as you suggested, would be to make local
functions (and pointers to them) a different category, as
are non-static class member functions (and pointers to them).

Given the amount of complexity, and that you can get many of
the effects of local functions with function objects or with
classes in general, adding local functions didn't seem like
a big win for C++.

--
Steve Clamage, stephen.clamage@sun.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              ]




