Article View: comp.std.c
Article #3442Re: Nested functions (was: Re: GOTO single exit point)
From: Rod Burman
Date: Tue, 26 Sep 1995 22:24
Date: Tue, 26 Sep 1995 22:24
55 lines
2954 bytes
2954 bytes
How about this as an implimentation technique "in the spirit of C"
-- the programmer gets to say what she want's
-- but only she has to pay for it
-- blatantly cribbed from "normal" C++ implimentations
int func_with_nested_funcs(/*args*/)
{
int i;
char c;
long l;
/* other variables & code */
/* compiler generates a "struct" definition for all the variables
say __compiler_gen_struct_func_with_nested_funcs__ and passes a pointer
for this to each nested function which use it to access these variables
-- we can flag we don't need this access (e.g. for the compare function
for qsort case by explicitly "void"ing the zeroth (usually invisble) this
pointer position */
int nested_0(<invisible "this" pointer> /* other args */)
{
/* body -- may use i, c & l via "this" */
}
char *nested_1(void /*, possibly other args */)
{
/* can't use i, c or l since we have inidicated via the
explicit void that we don't want "this" */
}
/* etc */
}
If we take a pointer for nested_0 we must supply the this pointer
ourselves (easy if we put all func_with_nested_funcs variables in a
named struct, otherwise an exercise in programmer ingenuity) thus outside
the function nested_0 has prototype "int nested_0(void *, ....)"
-- borrowing again from C++ may be we allow "const" after the function
which would allow:
int nested_2(/* args */) const { /* implimentation */ }
=> called like int nested_2(const void* /* args */
if we take a pointer to nested_1 we don't have the invisible stuff,
presumably because we don't need it and the "external" prototype is
the same as the internal one.
This looks like it should work for all C compilers, requires just one
new keyword "this" (possible not even that) -- and two more overloaded
ones (const and void) (more meanings for the same words surely the
essence of the spirit of C!)
So where did I go wrong? Surely it can't really be this easy?
Rod B
Not even speaking for himself....
Technical Details
Message-ID:
<449ui8$5g@news.bridge.com>Path:
arc1-ca.pugleaf.net!news.bridge.com!newsReferences:
<3vn1ht$kj8@martha.utk.edu> <41cke4$gtd@sparcserver.lrz-muenchen.de> <41glno$3a0@caip.rutgers.edu> <41iebe$kec@news0.rain.rg.net> <41pm80$skp@inferno.mpx.com.au> <DE02nC.B58@eskimo.com> <41t0sb$15e@news0.rain.rg.net> <DE6G2z.JJD@crdnns.crd.ge <43v2a8$b2g@hermes.acs.unt.edu> <KANZE.95Sep25115042@slsvhdt.lts.sel.alcatel.de> <446ss1$deg@news0.rain.rg.net> <KANZE.95Sep26113747@slsvhdt.lts.sel.alcatel.de>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.bridge.com!news From: Rod Burman <rodb@bridge.com> Newsgroups: comp.std.c,comp.lang.c Subject: Re: Nested functions (was: Re: GOTO single exit point) Date: 26 Sep 1995 22:24:08 GMT Organization: Bridge Information Systems Inc. Message-ID: <449ui8$5g@news.bridge.com> References: <3vn1ht$kj8@martha.utk.edu> <41cke4$gtd@sparcserver.lrz-muenchen.de> <41glno$3a0@caip.rutgers.edu> <41iebe$kec@news0.rain.rg.net> <41pm80$skp@inferno.mpx.com.au> <DE02nC.B58@eskimo.com> <41t0sb$15e@news0.rain.rg.net> <DE6G2z.JJD@crdnns.crd.ge <43v2a8$b2g@hermes.acs.unt.edu> <KANZE.95Sep25115042@slsvhdt.lts.sel.alcatel.de> <446ss1$deg@news0.rain.rg.net> <KANZE.95Sep26113747@slsvhdt.lts.sel.alcatel.de> NNTP-Posting-Host: 167.76.15.104 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 1.2b6 (Windows; I; 32bit)