comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Limited object by reference or access argument?
Date: Mon, 7 Aug 2017 18:31:41 -0500
Date: 2017-08-07T18:31:41-05:00	[thread overview]
Message-ID: <omat8u$sf7$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: om88a9$1kis$1@gioia.aioe.org

"Victor Porton" <porton@narod.ru> wrote in message 
news:om88a9$1kis$1@gioia.aioe.org...
...
>> It may work like this (in fact it is more complex):
>>
>> type World_Type is tagged limited
>>    record
>>       Handler: access BNode_ID_Handler'Class;
>>    end;
>>
>> procedure Set_Handler (World: World_Type;
>>                        Handler: BNode_ID_Handler'Class) is
>> begin
>>    World.Handler := Handler'Unchecked_Access;
>> end;

If you had written instead:

procedure Set_Handler (World: World_Type;
                        Handler: access BNode_ID_Handler'Class) is
begin
    World.Handler := Handler; -- (1)
end;

Program_Error will be raised at (1) if you passed a local object as a 
handler. Bob Duff calls that a "tripping hazard", and I agree. It's the sort 
of thing that gets by testing and only breaks at the worst possible time. 
Avoid anonymous access types!!

                                        Randy.


  parent reply	other threads:[~2017-08-07 23:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-06 21:16 Limited object by reference or access argument? Victor Porton
2017-08-06 22:01 ` Victor Porton
2017-08-06 23:21   ` Victor Porton
2017-08-07  0:35     ` Victor Porton
2017-08-07 23:31     ` Randy Brukardt [this message]
2017-08-07 14:10 ` Jere
2017-08-07 23:28 ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox