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 20:37:30 +0200
Date: 2014-02-06T20:37:30+02:00	[thread overview]
Message-ID: <bli330Fl1b0U1@mid.individual.net> (raw)
In-Reply-To: <a79c11d5-d1cf-4ee0-9647-b286272a0a76@googlegroups.com>

On 14-02-06 20:03 , adambeneschan@gmail.com wrote:
> On Thursday, February 6, 2014 9:30:32 AM UTC-8, Niklas Holsti wrote:
> 
>> (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.)
> 
> That actually isn't true.

It is here, I think, because the upper bound comes from a discriminant,
where subtypes are checked more strictly. And the lower bound is fixed
to zero, so only a negative upper bound makes an empty range.

> The bounds of an empty range do *not* need
> to be within the subrange.  Here, Natural is a subrange 0 ..
> Integer'Last, but Integer is the base type, and as long as the bounds
> belong to the base type, it's OK.

Agreed. But if I have

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

then I'm pretty sure that the declaration

   M : Memory_Block (last => -1);

will be rejected, because -1 is not in Natural. GNAT says:

mb.adb:15:30: warning: static value out of range of type "Standard.Natural"
mb.adb:15:30: warning: "Constraint_Error" will be raised at run time

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

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