From 1183035127691841996
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/11
Message-ID: <lz%73.9759$wk2.183779@newscene.newscene.com>#1/1
X-Deja-AN: 488251804
X-NNTP-Posting-Host: 209.173.92.180
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> <37dd56e1.565652003@nntp.ix.netcom.com>
X-Trace: newscene.newscene.com 929072465 209.173.92.180 (Thu, 10 Jun 1999 22:41:05 CDT)
Organization: Newscene Public Access Usenet News Service (http://www.newscene.com/)
NNTP-Posting-Date: Thu, 10 Jun 1999 22:41:05 CDT
Newsgroups: comp.std.c++
Originator: clamage@taumet


source@netcom.com (David Harmon) wrote:

: Also, a local function can only be called from within the context of a
: function that knows about it.

s type.  Not it.

: Returning a pointer to a local function
: would be undefined, just like returning a pointer to an auto variable.

Functions by their nature are not auto, they are static.

typedef int (*fp) (int);
int a (int v) { return v & 1; }
fp pick_a_func () {
   int b (int v) { return v * v; }
   return rand() & 1 ? a : b;
   }

Or did you mean that returning a pointer to a local function would
need to be made a special case and disallowed?  So assign it to a
global variable.  Disallow that also?  Pass it to another function
which makes the assignment.  Disallow passing it to another function?
That was the reason for wanting it.

On the system that I use, there would be no overhead.  In C a pointer
to function points to a struct which contains the address of the
function, other stuff and the display.  I am already paying the
expense of the concept.  A function pointer dereference requires
two levels of indirection.

I've seen it.  I've broken it.  I don't want it.

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              ]




