comp.lang.ada
 help / color / mirror / Atom feed
From: "G.B." <rm-dash-bau-haus@dash.futureapps.de>
Subject: Re: Need help for constrained type
Date: Thu, 06 Feb 2014 18:37:01 +0100
Date: 2014-02-06T18:37:00+01:00	[thread overview]
Message-ID: <52f3c83c$0$6559$9b4e6d93@newsspool4.arcor-online.net> (raw)
In-Reply-To: <e16cb161-a199-48b1-ac53-a783198da0ac@googlegroups.com>

On 06.02.14 17:13, Gerd wrote:
> Is it possible to allocate "len" units, but address them from 0 .. len - 1?
>
> How can I do this?

One approximation can make use of generics. The immediate
mention of the Len with the object declaration will not be
present. But otherwise the approximation preserves the
"interface" of Memory_Block, except that the .Len component
is no longer constant, and not guaranteed to be in sync with
the length of .Usage_Info, if someone messes with it.

    generic
       Len : Natural;
    package Memory_Blocks is

       C_Style_Len : constant Integer := Len - 1;

       type Memory_Block is
          record
             Len : Natural := Memory_Blocks.Len;
             Start_Address : Mem_Addr;
             Block_Size : Natural;
             Usage_Info : Mem_Array (0..C_Style_Len);
          end record;

    end Memory_Blocks;

    package C_Style_Mem is new Memory_Blocks (2**16);

    mem : C_Style_Mem.Memory_Block;


(A different approach might instead choose a function,
C_Length (a renaming of Integer'Pred), such that

    mem : Memory_Block (C_Length (2**16));

will in effect let the index of Mem_Array be 0 .. Len.)


  parent reply	other threads:[~2014-02-06 17:37 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
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. [this message]
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