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,e4e9809bdf82397f X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: Newbie Access Types Date: 1999/08/18 Message-ID: <37bb0f72@news1.us.ibm.net>#1/1 X-Deja-AN: 514337916 Content-transfer-encoding: 7bit References: <7pe6tg$dqq$1@dailyplanet.wam.umd.edu> X-Trace: 18 Aug 1999 19:54:26 GMT, 32.101.8.213 Organization: Global Network Services - Remote Access Mail & News Services X-Notice: should be reported to postmaster@ibm.net Content-Type: text/plain; charset="US-ASCII" Mime-version: 1.0 Newsgroups: comp.lang.ada X-Complaints-To: postmaster@ibm.net Date: 1999-08-18T00:00:00+00:00 List-Id: In article <7pe6tg$dqq$1@dailyplanet.wam.umd.edu> , rayoub@wam.umd.edu (Ronald Ayoub) wrote: > I have read that an access type parameter is always copied in even when > the parameter is an out parameter and that this is so that the access type > is not undefined which can cause problem. Yes, access objects are always passed by copy. > Could someone please elaborate on this? It is my thought that access types are > initialized to null when not explicitly initialized so that an uncopied access > type going into a function will only result in the formal parameter being > initialized to null. You definately want to read section 8.2.2 of the Ada83 Rationale. It is available online, but I have included that section here too. Text format at adahome: HTML format at adaic: Matt (start of excerpt from Ada83 Rationale) 8.2.2 The Effect of Parameter Passing Mechanisms for Access Types A difficulty of a different nature arises for parameter passing by reference in the case of access types. Consider for example a procedure to delete a given element from a list (see section 6.3.6): type PLACE; type LIST is access PLACE; type PLACE is record SUCC : LIST; PRED : LIST; CONTENT : ITEM; end record; ... E : LIST; procedure DELETE(L : in LIST) is begin L.SUCC.PRED := L.PRED; L.PRED.SUCC := L.SUCC; L.SUCC := null; L.PRED := null; end; This is the conventional way of deleting an element from a doubly- linked list, and a call such as DELETE(X); will work regardless of whether parameter passing is achieved by reference or by copy. Consider however the procedure call DELETE(E.PRED); where we assume the list to be in the following state before the call: place: A B C D E F successor: B C D E F ... predecessor: ... A B C D E If parameter passing is by copy, we achieve the desired effect of deleting D (the predecessor of E) and we obtain the state place: A B C D E F successor: B C E null F ... predecessor: ... A B null C E If parameter passing is by reference, then the formal parameter L will refer to the object E.PRED. The first assignment will have the expected effect of establishing E.PRED = C. But this means that the remaining statements will operate on C (rather than D) and will not achieve what we want: the second assignment will achieve B.SUCC = D; and the last two assignments will unlink C (rather than D), leaving the list in a state of chaos: place: A B C D E F successor: B D null E F ... predecessor: ... A null C C E One possible reaction to this example is to consider that parameter passing by reference is legitimate for access types, and that we are just confronted with an incorrect program. Our preferred viewpoint is rather to consider that access types are already unique in that the programmer is permitted explicitly to manipulate references and construct aliases: This is the purpose of access types, and a programmer using such types is asserting that he wishes to take control of all references and aliases. Accordingly, the parameter passing should not generate extra references and aliases of which the programmer is unaware; therefore, all parameter passing for access types should be by copy. A final problem with parameter passing by reference is that this mechanism will be almost impossible to achieve (or at least, very costly) on distributed systems and whenever we deal with systems with multiple address spaces. (end of excerpt)