From: madmats@elma.epfl.ch (Mats Weber)
Subject: Overloading of assignment
Date: 25 Nov 88 12:09:10 GMT [thread overview]
Message-ID: <881125130910.218003ab@elcc.epfl.ch> (raw)
The question of what an overloaed assignment procedure should look like still
remains:
variant A:
procedure ":=" (OBJECT : out SOME_LIMITED_TYPE;
VALUE : in SOME_LIMITED_TYPE);
variant B:
procedure ":=" (OBJECT : in out SOME_LIMITED_TYPE;
VALUE : in SOME_LIMITED_TYPE);
The problem with variant A is that if SOME_LIMITED_TYPE has subcomponents that
are of an access type, then no garbage collection can be performed on OBJECT
before assigning it its new value, because OBJECT cannot be read inside ":=".
The problem with variant B is that it cannot be used for the initialization
of an object (unless SOME_LIMITED_TYPE is an array or record type) because the
actual parameter for OBJECT must have a defined value before the use of ":="
(otherwise the program is erroneous). Consider the following example:
package ADT is
type T is limited private;
procedure ":=" (OBJECT : in out T; VALUE : in T);
function TO_T (N : INTEGER) return T;
private
type T is range 0..1000;
end ADT;
with ADT;
procedure P is
X : ADT.T;
use ADT;
begin
X := TO_T(7); -- this call of ":=" is erroneous because X
end P; -- is undefined.
Variant A is better if SOME_LIMITED_TYPE is a scalar type,
variant B is better if SOME_LIMITED_TYPE is an array or record type,
both variants work with access types as these always have the initial value
null.
Personally, I think the rules on assignment in Ada cannot be changed if
upward compatibility is to be acheived.
Mats Weber
DI-LITh-EPFL
Swiss Federal Institute of Technology
1015 Lausanne
Switzerland
e-mail : madmats@elma.epfl.ch
next reply other threads:[~1988-11-25 12:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1988-11-25 12:09 Mats Weber [this message]
1988-11-26 19:59 ` Overloading of assignment William Thomas Wolfe,2847,
1988-11-26 20:10 ` William Thomas Wolfe,2847,
1988-11-29 16:01 ` Stephe Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox