🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #243

Re: Can you nest subroutines in C?

#243
From: Wade Bickel
Date: Wed, 28 Jun 1989 11:17
56 lines
2879 bytes
shadow@pawl.rpi.edu (Deven T. Corzine) writes:
>One midpoint approach is to put the data values in a structure, and
>pass a pointer to the structure.  This still involves passing an extra
>parameter, but avoids duplicating the data unnecessarily.  Another

        I've considered this, but it will make what was an easy, maintainable
codeing trick into a mess.

>approach is to make a function with its "nested" functions a separate
>module, with variables global to the module, but not defined external
>to the module.  I can't remember offhand how to declare such; maybe
>"static int x" outside of function defintions would do it.  (need to
>override the otherwise assumed extern)  Anyone have K&R's book handy?
>(Note that this method is NOT reentrant, but passing pointers (held in
>local variables) to dynamically allocated memory IS reentrant.)

        Use of "static" vars in a seperate modules has been suggested by
many via E-Mail.  This solution breaks down under recursion.

>
>Although slightly more work, using AllocMem (or malloc) and passing
>arounds pointers (to a structure if many discrete variables, like a
>bunch of integers -- or maybe an array if appropriate) is equally
>memory-efficient, and reentrant.

        This seems to me a quick way to make your code un-maintainable.
Following recursive code is hard enough without crowding it with unneeded
structures and Alloc() calls.  Also, since the Alloc() may fail, it leads
to bigger code as well.

>
>Yes, C is a powerful and flexible language, even if somewhat terse.
>(I know that *I* like it!)

        So I thought as well.  I too really like the tersness of C.  However
I have now found something of major significants which I can do in M2 but not
in C.  Nested subroutines prevent spagetti code, which is very common in C.
I used to wonder as I would translate C to M2 why globals were so heavily
used, often wondering if this was a sign that the programmer was of
questionable talent, leading me to re-organize/re-write the code.  Now I see
why this is done.  Very UGLY :^<

        So far I have found nothing I could do in C that I could not do in
M2.  To me this is the test of a Language.


                                         Thanks to all who sent me mail,


                                                                Wade.
>
>Deven

UUCP: {nosc ucsd hplabs!hp-sdd}!crash!pnet01!wade
ARPA: crash!pnet01!wade@nosc.mil
INET: wade@pnet01.cts.com
Technical Details
Message-ID: <4495@crash.cts.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!ucsd!sdcsvax!ucsdhub!hp-sdd!ncr-sd!crash!pnet01!wade

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!ucsd!sdcsvax!ucsdhub!hp-sdd!ncr-sd!crash!pnet01!wade
From: wade@pnet01.cts.com (Wade Bickel)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Can you nest subroutines in C?
Message-ID: <4495@crash.cts.com>
Date: 28 Jun 89 11:17:26 GMT
Sender: news@crash.cts.com
Organization: People-Net [pnet01], El Cajon CA
Lines: 56