comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org>
Subject: Re: Passing the same actual as both in and out formal parameters?
Date: Tue, 17 Nov 2009 20:47:53 -0700
Date: 2009-11-17T20:47:53-07:00	[thread overview]
Message-ID: <hdvqkr$et2$1@news.tornevall.net> (raw)
In-Reply-To: <d21bd72b-be0a-4c16-a33e-1b96555acaa4@a39g2000pre.googlegroups.com>

Adam Beneschan wrote:
> On Nov 17, 4:11 pm, "Jeffrey R. Carter"
> <spam.jrcarter....@spam.acm.org> wrote:
>>
>> pragma Assert (A'access /= B'access);
> 
> First of all, for this to work in the general case, that would need a
> major change in language semantics, since you need an access type in
> order for 'Access to be allowed.  The only way this would be legal is
> if there happened to be exactly one "=" operator directly visible with
> operands of some named access-to-T type.  (Also, if "=" were
> overridden with a user-defined operator that did something unexpected,
> it would fail, but nobody would do that.)

OK. Since this in the body of the operation, it seems doable:

procedure P (A : in T; B : out T) is
    type T_Ptr is access T;

    A_Ptr : constant T_Ptr := A'access;
    B_Ptr : constant T_Ptr := B'access;

    pragma Assert (A_Ptr /= B_Ptr);

So you're guaranteed that "=" for T_Ptr is used, and you know it hasn't been 
overridden.

What about 'Address?

> Second, it only catches the case where the operands are of the same
> type; it won't catch other overlaps such as
> 
>    P2 (A => Object, B => Object.Component);

Sure, it's not a general solution; I doubt if there could be one. But it does 
seem to serve for the OP's case.

-- 
Jeff Carter
"You cheesy lot of second-hand electric donkey-bottom biters."
Monty Python & the Holy Grail
14



      reply	other threads:[~2009-11-18  3:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-17  9:50 Passing the same actual as both in and out formal parameters? Ludovic Brenta
2009-11-17 10:31 ` Jean-Pierre Rosen
2009-11-17 11:26   ` Ludovic Brenta
2009-11-17 13:13     ` Jean-Pierre Rosen
2009-11-17 16:07       ` Ludovic Brenta
2009-11-18 10:00         ` Jean-Pierre Rosen
2009-11-17 10:40 ` Niklas Holsti
2009-11-17 16:26 ` Adam Beneschan
2009-11-17 21:25   ` Randy Brukardt
2009-11-18  0:11     ` Jeffrey R. Carter
2009-11-18  0:23       ` Adam Beneschan
2009-11-18  3:47         ` Jeffrey R. Carter [this message]
replies disabled

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