comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Eachus <rieachus@comcast.net>
Subject: Re: Trying to declare an array from the heap from inside a record declaration
Date: Tue, 14 Nov 2017 07:19:55 -0800 (PST)
Date: 2017-11-14T07:19:55-08:00	[thread overview]
Message-ID: <6f3764b9-4260-4ebd-9a10-7cc47a5647b9@googlegroups.com> (raw)
In-Reply-To: <79108071-7d76-4276-bc14-268bc1b74b8a@googlegroups.com>

On Friday, November 10, 2017 at 3:10:46 AM UTC-5, AdaMagica wrote:

> Because Ada syntax does not allow it.
> 
> The question should be: Why does Ada not allow this? Ask the language lawywers! (I myself am not in favour of this idea (renamings inside a record).)

-- Probably because the result would not be what the user wants.  If you
-- allocate the array on the heap:

    X_Ptr : constant Real_Vector_Access := new Real_Vector(M .. N); 

-- You can then create a record containing 'X':

    type Foo is record
      X: Real_Vector_Access := X_Ptr;
    end record;

-- And you have data on the heap.  If you want to access elements of X_Ptr
-- incuding to assign to them Foo.X(1,2) works. If you want to create a copy
-- of X_Ptr.all (or Foo.X.all) you need the all.  If you just want to copy
-- the pointer, no .all, and that is probably what you should be doing
-- anyway.  I assume you put the object on the heap because it was too big
-- to fit on the stack, or you wanted to pass it around (in a compact form).

      reply	other threads:[~2017-11-14 15:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-08  9:32 Trying to declare an array from the heap from inside a record declaration Jerry
2017-11-08 13:08 ` AdaMagica
2017-11-08 17:22 ` Jeffrey R. Carter
2017-11-10  7:44 ` Jerry
2017-11-10  8:10   ` AdaMagica
2017-11-14 15:19     ` Robert Eachus [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