Article View: comp.std.c
Article #3443Re: Nested functions (was: Re: GOTO single exit point)
From: Rod Burman
Date: Wed, 27 Sep 1995 13:22
Date: Wed, 27 Sep 1995 13:22
72 lines
3585 bytes
3585 bytes
Having thought about this some more, while walking the dog I would like
to re-work it slightly to give (changes marked by ***):
Rod Burman <rodb@bridge.com> wrote:
>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> /* possibly other args */)
> {
> /* body -- may use i, c & l via "this" */
> }
>
*** static char *nested_1(/* possibly other args */)
> {
> /* can't use i, c or l since we have inidicated via the
*** "static" 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(__compiler_gen_struct_func_with_nested_funcs__*, ....)"
>-- 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 __compiler_gen_struct_func_with_nested_funcs__* /*
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" -- and two more overloaded ones
*** (const and static) (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?
We probably do want/need this as a keyword for dis-ambiguation and
knowing we are supplied the enclosing variables e.g.
nested_x ()
{
int i = this ? this->i : 42; /* caller supplied stuff or default? */
/* etc */
}
may be we don't want to call it this though (that?)
Rod B
Not even speaking for himself....
Technical Details
Message-ID:
<44bj6h$hp8@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> <449ui8$5g@news.bridge.com>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: 27 Sep 1995 13:22:25 GMT Organization: Bridge Information Systems Inc. Message-ID: <44bj6h$hp8@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> <449ui8$5g@news.bridge.com> 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)