From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,88e7ef9008757431 X-Google-Attributes: gid103376,public From: Francois Godme Subject: Re: Function Calls by Address Date: 1999/09/06 Message-ID: <37D2F41D.AE1C85F5@magic.fr>#1/1 X-Deja-AN: 521473332 Content-Transfer-Encoding: 7bit References: <37CADE68.6AF06F5D@escmail.orl.lmco.com> <37CEEFFA.7D73F78D@magic.fr> <7qooh7$hbh$1@nnrp1.deja.com> <37CFFEA6.921CBE59@magic.fr> <7qsrtj$9lp$1@nnrp1.deja.com> X-Client: Magic On Line [unknown@ppp-46.net4.magic.fr] X-Accept-Language: fr Content-Type: text/plain; charset=us-ascii Organization: very little Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-09-06T00:00:00+00:00 List-Id: Robert Dewar wrote: > In article , > mario@klebsch.de (Mario Klebsch) wrote: > > ANd there are a lot of nice things, you only can to that > elegant with > > nested procedures. Nested procedures have full access to all > local > > variables of the enclosing procedures. If you want to do it in > C, you > > have to use static variables and will loose reentrancy. > > Right Mario, this is a VERY important point. It is often > the reason for C library routines being non-thread safe. > Unfortunately the fix in these C library routines is > often to add locks to protect these unnecessary global > variables. > > As an example, suppose you are writing printf. Well you > certainly do not want to write this as one giant function, > so you write it as multiple functions. Now you *should* > pass around all global variables, such as the buffer into > which characters are being written, but it is awfully tempting > to make this a global variable, with the result that you lose > thread safety. In Ada, you would write printf with nested > subprograms that accessed the buffer pointer as a non-local > uplevel reference (but the variable would be local to printf > itself). > > With regard to name space pollution, it is more than just this. > The point is that if you see a nested procedure, you know > immediately that you only have to understand it in the context > of its enclosing procedure, and indeed if you can ignore this > code in the reading you are doing right now, you can immediately > and easily ignore all the nested procedures, knowing that you > have not missed anything. > > Sent via Deja.com http://www.deja.com/ > Share what you know. Learn what you don't. There are two kinds of nested procedures: the ones which do not make uplevel references and the others which do. You gain possible reuses by unnesting the former. You gain clarity by rewritting the latter to avoid the uplevel references. All the hidden parameters as well as their passing modes are then shown. What was previously written has a function is now correctly expressed as a procedure if for example one uplevel reference was modified.