comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Re: Ada Alternatives to Unrestricted_Access
Date: Thu, 8 Mar 2018 16:52:48 -0800 (PST)
Date: 2018-03-08T16:52:48-08:00	[thread overview]
Message-ID: <cc0c00d3-f45f-4043-880f-d7f29cc71e2c@googlegroups.com> (raw)
In-Reply-To: <86b8ddee-fef0-426b-af90-c6f5ce9c9d93@googlegroups.com>

On Thursday, March 8, 2018 at 7:43:31 PM UTC-5, Jere wrote:
> On Thursday, March 8, 2018 at 3:27:02 AM UTC-5, Dmitry A. Kazakov wrote:
> > On 07/03/2018 23:29, Jere wrote:
> > > On Wednesday, March 7, 2018 at 3:38:13 PM UTC-5, Dmitry A. Kazakov wrote:
> > >> On 2018-03-07 21:11, Jere wrote:
> > 
> > >>> Since the Container
> > >>> implementation is unknown in the generic, I wasn't able to get a version
> > >>> of the Rosen technique to work as an alternative (same constant vs
> > >>> variable access problem).
> > >>
> > >> I am not sure I understand the problem. Why don't you pass a function
> > >> Self along with the container type:
> > >>
> > >>      generic
> > >>         type Container is tagged whatever;
> > >>         function Self (C : Container'Class)
> > >>            return not null access Container'Class;
> > >>      package Iterative_Mess is
> > > 
> > > Because the package is already in use in other code, so
> > > changing the specification would be a very time consuming
> > > change.
> > 
> > You can default Self when not used.
> > 
> > -- 
> > Regards,
> > Dmitry A. Kazakov
> > http://www.dmitry-kazakov.de
> 
> So I tried playing with this, but I still ran into the same
> problem when trying to implement the Self function.  Inside
> I needed to "un-const" the container, so I came back to this
> same problem.

Example:
with Ada.Text_IO; use Ada.Text_IO;
with System.Address_To_Access_Conversions;

procedure jdoodle is
    type Container is tagged null record;
    
    package A2A is new System.Address_To_Access_Conversions(Container);
    
    type Container_Access is access Container;
    type Container_Constant_Access is access constant Container;
    
    function Self 
        (C : Container'Class)
         return not null access Container'Class
    is begin
        --return C'Unchecked_Access;  --ERROR: access-to-variable designates constant
        --return C'Unrestricted_Access;  -- Works, but not portable, GNAT specific
        return A2A.To_Pointer(C'Address);  -- Also works, unsure if OK in portable Ada
    end Self;
     
begin
    null;
end jdoodle;


  reply	other threads:[~2018-03-09  0:52 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-07 20:11 Ada Alternatives to Unrestricted_Access Jere
2018-03-07 20:38 ` Dmitry A. Kazakov
2018-03-07 22:29   ` Jere
2018-03-08  8:27     ` Dmitry A. Kazakov
2018-03-09  0:43       ` Jere
2018-03-09  0:52         ` Jere [this message]
2018-03-09  8:28           ` Dmitry A. Kazakov
2018-03-11  0:31             ` Jere
2018-03-08  3:18 ` gautier_niouzes
2018-03-09  0:41   ` Jere
2018-03-08 17:51 ` Jeffrey R. Carter
2018-03-09  0:36   ` Jere
2018-03-09 16:46     ` Jeffrey R. Carter
2018-03-11  0:38       ` Jere
2018-03-11  9:57         ` Jeffrey R. Carter
2018-03-11 10:44           ` Dmitry A. Kazakov
2018-03-11 14:31           ` Jere
2018-03-11 15:49             ` Jeffrey R. Carter
2018-03-11 17:33               ` Jere
2018-03-11 18:12                 ` Jeffrey R. Carter
2018-03-11 19:53                   ` Jere
2018-03-12 16:28                     ` Jeffrey R. Carter
2018-03-11 18:27                 ` Niklas Holsti
2018-03-11 20:07                   ` Jere
2018-03-12 23:35                     ` Randy Brukardt
2018-03-12 23:30         ` Randy Brukardt
2018-03-13  7:46           ` Niklas Holsti
replies disabled

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