I'm wondering about named access and anonymous access.
In the following Ada code, are the writing of parameter P1 type of
procedures PA and PB equivalent ?
package C1 is
type Inst is tagged null record;
type Class is access all Inst'Class;
end C1;
with C1;
package C2 is
type Inst is tagged null record;
type Class is access all Inst'Class;
procedure PA (Self : Inst; P1 : C1.Class); -- named access
procedure PB (Self : Inst; P1 : access C1.Inst'Class); -- anonymous access
end C2;
Same with:
function FA (Self : Inst) return C1.Class; -- named access
function FB (Self : Inst) return access C1.Inst'Class; -- anonymous access
Are FA and FB writing equivalent?
If not why?
In the following Ada code, are the writing of parameter P1 type of
procedures PA and PB equivalent ?
I'm wondering about named access and anonymous access.
On 2023-09-06 16:37, Blady wrote:
I'm wondering about named access and anonymous access.
In the following Ada code, are the writing of parameter P1 type of
procedures PA and PB equivalent ?
package C1 is
type Inst is tagged null record;
type Class is access all Inst'Class;
end C1;
with C1;
package C2 is
type Inst is tagged null record;
type Class is access all Inst'Class;
procedure PA (Self : Inst; P1 : C1.Class); -- named access
procedure PB (Self : Inst; P1 : access C1.Inst'Class); -- anonymous
access
end C2;
Same with:
function FA (Self : Inst) return C1.Class; -- named access
function FB (Self : Inst) return access C1.Inst'Class; -- anonymous
access
Are FA and FB writing equivalent?
If not why?
They are not equivalent from the access checks point of view:
declare
Y : C2.Inst;
X : aliased C1.Inst;
begin
C2.PA (Y, X'Access); -- Non-local pointer error
C2.PB (Y, X'Access); -- Fine
end;
Furthermore, tagged anonymous access is controlling (dispatches) when
not class-wide.
Why choosing named access for New_BorderLayout and anonymous access for AddLayoutComponent or GetLayoutComponent for the type of parameters P1_xxx and
the return type?
On 2023-09-07 18:06, Blady wrote:
Why choosing named access for New_BorderLayout and anonymous access
for AddLayoutComponent or GetLayoutComponent for the type of
parameters P1_xxx and the return type?
It's very poor design to have access types in the visible part of a non-private pkg spec.
Well, I was questioning myself about the choice between named access and anonymous access in the old Ada port of Java library, for instance:
type Typ;
type Ref is access all Typ'Class;
type Typ(LayoutManager2_I : Java.Awt.LayoutManager2.Ref;
Serializable_I : Java.Io.Serializable.Ref)
is new Java.Lang.Object.Typ
with null record;
------------------------------
-- Constructor Declarations --
------------------------------
function New_BorderLayout (This : Ref := null)
return Ref;
Why not all named or all anonymous ?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 335 |
Nodes: | 16 (2 / 14) |
Uptime: | 147:48:31 |
Calls: | 7,411 |
Calls today: | 1 |
Files: | 12,670 |
Messages: | 5,613,095 |