From -6809504776311866361
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,fb1a92fa405c930c
X-Google-Attributes: gidf78e5,public
From: James.Kanze@dresdner-bank.com
Subject: Re: nested functions
Date: 1999/06/23
Message-ID: <7k5v87$qqf$1@nnrp1.deja.com>#1/1
X-Deja-AN: 492912511
Approved: Valentin Bonnard <bonnard@clipper.ens.fr>
References: <7jrqf5$op5$1@nnrp1.deja.com> <7jrv0r$dfq$1@engnews1.eng.sun.com> <081650426190c69CPIMSSMTPU07@email.msn.com> <7k0b01$nod$1@panix.com> <7k3fr2$7el@abyss.West.Sun.COM>
X-Original-Date: Tue, 15 Jun 1999 16:33:11 GMT
X-Http-User-Agent: Mozilla/4.6 [en] (WinNT; I)
X-Http-Proxy: 1.0 x32.deja.com:80 (Squid/1.1.22) for client 193.194.7.71
Organization: Deja.com - Share what you know. Learn what you don't.
X-Article-Creation-Date: Tue Jun 15 16:33:11 1999 GMT
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUAN3DNTqwEuYhIxRhxAQFoVQH/WTXdY98QOyMoXBwq3m955kgBKy8YAD6p RSm23qzVpjEbFWbbqAyOS3uMwxst+6w0+72sEssKT5St3KahPUJoeQ== =gOvu
Newsgroups: comp.std.c++

In article <7k3fr2$7el@abyss.West.Sun.COM>,
  stanley@West.Sun.COM (Stanley Friesen [Contractor]) wrote:
> In article <7k0b01$nod$1@panix.com>,
> Greg Comeau <comeau@comeaucomputing.com> wrote:
> >scope is a syntactic thing.  It doesn't apply to a running program
> >in the same sense.

> True - but there is this little rule that variables of automatic
> *duration* are destroyed on exit from their scope.

On *final* exit from their scope.

> >  So, when you say the local vars do not exist when you leave the
> >scope, they will if the local function calls a different function,
> >perhaps passing or having pointers to the local vars.

> But if the destructors have been called on them, and the sotrage
> reused for some other set of automatic variables (as is allowed upon
> leaving a function), then those pointers generate undefined behavior,
> as they are pointers to variables after their destructors are called.

I'm pretty sure what Greg is talking about is nested function calls.
Consider the following:

    void
    f( int* pi )
    {
        ++ (*pi) ;
    }

    void
    g()
    {
        int                 x = 0 ;
        f( &x ) ;
        cout << x << '\n' ;
    }

You pass the address of a local variable to another function (eventually
in another compilation unit).  If C/C++ had nested functions, I would
expect to be able to do exactly the same thing with the address of the
nested function.

--
James Kanze                         mailto:
James.Kanze@dresdner-bank.com
Conseils en informatique orientie objet/
                        Beratung in objekt orientierter
Datenverarbeitung
Ziegelh|ttenweg 17a, 60598 Frankfurt, Germany  Tel. +49 (069) 63 19 86
27


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ 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              ]



