comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Need help for constrained type
Date: Thu, 06 Feb 2014 19:30:32 +0200
Date: 2014-02-06T19:30:32+02:00	[thread overview]
Message-ID: <blhv5eFk654U1@mid.individual.net> (raw)
In-Reply-To: <e16cb161-a199-48b1-ac53-a783198da0ac@googlegroups.com>

On 14-02-06 18:13 , Gerd wrote:

>   type Memory_Block (len : Natural) is
>     record
>       Start_Address : Mem_Addr;
>       Block_Size : Natural;
>       Usage_Info : Mem_Array (0..len-1);
>     end record;
> 
> the compiler tells me that this is not allowed.
> 
> Is it possible to allocate "len" units, but address them from 0 .. len - 1?
> 
> How can I do this?

This restriction sometimes annoys me too. You can pass a record
discriminant to a component, but you cannot alter it in any way, such as
by adding or subtracting something. So the only possibility is to change
the meaning of the discriminant to be "len - 1":

  type Memory_Block (last : Natural) is
    record
      Start_Address : Mem_Addr;
      Block_Size : Natural;
      Usage_Info : Mem_Array (0..last);
    end record;

(If you want to allow an empty Usage_Info, indexed 0..-1 for example,
you must of course declare Memory_Block.last using some range which
includes negative numbers, for example Integer.)

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .

  reply	other threads:[~2014-02-06 17:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-06 16:13 Need help for constrained type Gerd
2014-02-06 17:30 ` Niklas Holsti [this message]
2014-02-06 18:03   ` adambeneschan
2014-02-06 18:37     ` Niklas Holsti
2014-02-06 18:57       ` adambeneschan
2014-02-06 17:37 ` G.B.
2014-02-07 14:11   ` Mike H
2014-02-10 11:40     ` G.B.
2014-02-07  0:04 ` Jeffrey Carter
replies disabled

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