comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Aliased
Date: 29 Jun 2005 17:10:15 -0400
Date: 2005-06-29T17:10:15-04:00	[thread overview]
Message-ID: <wcc3br0c1jc.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 1118930589.514028.150340@g47g2000cwa.googlegroups.com

nblanpain@hotmail.com writes:

> So this is my sources and the compilation error :
>
> ------ Container.ads
> generic
>    type T_Item is private;
>    Static_Size : Integer;
> package Container is
>    type T_Array is array (Integer range <>) of T_Item;
>    type A_Array is access all T_Array;
>    type T_Container is tagged record
>       Obj_Array : aliased T_Array (1..Static_Size);
>       Ptr_Array : A_Array;
>    end record;
>    procedure Initialize (This : in out T_Container; Dynamic_Size : in
> Integer);
>    function P_Array (This : in T_Container) return A_Array;
> end Container;

I have a package that tries to do something similar.
Try wrapping the array in a record:

    type T_Rec(Length: Natural) is
        record
            A: T_Array(1..Length);
        end record;
    type T_Rec_Ptr is access all T_Rec;
    type T_Container is tagged record
        Obj_Array : aliased T_Rec (Length => Static_Size);
        Ptr_Array : T_Rec_Ptr;
    end record;

Then Initialize can set Ptr_Array to either "new T_Rec(Length =>
Dynamic_Size)" or "This.Obj_Array'Access".

Well, you'll want to change the names of things to make sense...
    
> ------ Container.adb
> package body Container is
>    procedure Initialize (This : in out T_Container; Dynamic_Size : in
> Integer) is
>    begin
>       if Dynamic_Size /= 0 then
>          This.Ptr_Array := new T_Array (1.. Dynamic_Size);
>      elsif Static_Size /= 0 then
>         This.Ptr_Array := This.Obj_Array'Access; --- Compilation Error
>      end if;
>    end Initialize;
>    function P_Array (This : in T_Container) return A_Array is
>    begin
>       return This.Ptr_Array;
>    end P_Array;
> end Container;
> 
> -- Compilation Error : Object subtype must statically match designated
> subtype. No local pointer cannot point to local object.

- Bob



      parent reply	other threads:[~2005-06-29 21:10 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-15 16:06 Aliased nblanpain
2005-06-15 16:35 ` Aliased Martin Dowie
2005-06-15 18:56 ` Aliased nblanpain
2005-06-15 21:47   ` Aliased Martin Dowie
2005-06-16  3:15 ` Aliased Steve
2005-06-16 14:03   ` Aliased nblanpain
2005-06-16 19:56     ` Aliased Simon Wright
2005-06-17  7:01       ` Aliased nblanpain
2005-06-17  9:38         ` Aliased Larry Kilgallen
2005-06-19 19:44           ` Aliased nblanpain
2005-06-19 20:33             ` Aliased Jeffrey Carter
2005-06-20  9:34               ` Aliased nblanpain
2005-06-20 16:41                 ` Aliased Jeffrey Carter
2005-06-17  2:15     ` Aliased Jeffrey Carter
2005-06-17  7:02       ` Aliased nblanpain
2005-06-17  2:35     ` Aliased Steve
2005-06-17  7:52       ` Aliased Dmitry A. Kazakov
2005-06-17  4:38     ` Aliased Christoph Grein
2005-06-29 21:10     ` Robert A Duff [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