Thanks in advance.
Eric Marshall
System Development Corporation, a Burroughs Company
P.O. Box 517
Paoli, PA. 19301
(215) 648-7223
USENET: sdcrdcf!burdvax!eric
{sjuvax,ihnp4,akgua,cadre}psuvax1!burdvax!eric
ARPANET: PAYTON@BBNG
Consider the following procedure to delete an element from
a doubly linked list:
type Element;
type Ptr is access Element;
type Element is
record
Prev,
Succ : Ptr;
Data : some_type;
end record;
E : Ptr;
procedure Delete (P : in Ptr) is
begin
P.Succ.Pred := P.Pred;
P.Pred.Succ := P.Succ;
P.Succ := null;
P.Pred := null;
end;
A call to this procedure of the form
Delete (X);
will work regardless of the parameter passing mechanism. However,
consider now the call:
Delete (E.Pred);
where the linked list, before the call, has the state:
Element: A B C D E F
succ: B C D E F ...
pred: ... A B C D E
If the parameter passing mechanism is by copy, then the desired
effect is achieved, but pass-by-reference will not work (the list
ends up in a state of "chaos"). You can work out the details
yourself, or see Ichbiah's pictures.
The language designers chose to make pass-by-copy the rule to
eliminate problems such as the one above. Access types allow
the programmer to create and manage aliases. It was the view
of the language designers not to have parameter passing create
more aliases of which the programmer is unaware. Another
problem with pass-by-reference is in achieving the desired
semantics on distributed systems with multiple address spaces.
I'll let you ponder these ideas, and leave you with perhaps a
tangential question (the answer for which is similar to this
question):
Why, for mode out access type parameters, does Ada require
copy-in of the actual access value? Obviously the formal
cannot read the actual's value, so why require that it be
copied in? (somewhat of a trick question)
gom
-------
Mats_Ohlin_FOA2%QZCOM.MAILNET [@MULTICS.MIT.EDU]