comp.lang.ada
 help / color / mirror / Atom feed
From: Mark Lorenzen <mark.lorenzen@ofir.dk>
Subject: Re: strings and multidimensional arrays
Date: Mon, 13 Oct 2003 23:47:52 +0200
Date: 2003-10-13T23:47:52+02:00	[thread overview]
Message-ID: <m3u16cn71z.fsf@niflheim.malonet> (raw)
In-Reply-To: bmes2v$dma$1@sparta.btinternet.com

"Martin Dowie" <martin.dowie@btopenworld.com> writes:

> "Robert I. Eachus" <rieachus@comcast.net> wrote in message
> news:3F8ADB3D.5010000@comcast.net...
>>      type Unconstrained_Record (D : Disc := One) is record
>
> Isn't this the key line here? The default ("One") allows you to change it
> late (as often

Yes it is. If a record contains a variant_part and the discriminant
governing the variant_part has a default value, then it is allowed to
perform an assignment that changes the value of the discriminant and
therefore also the variant_part.

So the following is allowed:

procedure Option is
   type Optional_Integer (Defined : Boolean := False) is
      record
         case (Defined) is
            when True  => Value : Integer;
            when False => null;
         end case;
      end record;

   Integer_Value : Optional_Integer;

begin
   Integer_Value := Optional_Integer'(Defined => True, Value => 5);
   Integer_Value := Optional_Integer'(Defined => True, Value => 3);
   Integer_Value := Optional_Integer'(Defined => False);
end Option;

> as you like). If you didn't have this, then you would have to provide a
> value at
> declaration and it would be 'fixed' for the life of the object.

Also correct. The following is *not* legal:

procedure Option is
   type Optional_Integer (Defined : Boolean) is
      record
         case (Defined) is
            when True  => Value : Integer;
            when False => null;
         end case;
      end record;

   Integer_Value : Optional_Integer (Defined => True);

begin
   Integer_Value := Optional_Integer'(Defined => True, Value => 5);
   Integer_Value := Optional_Integer'(Defined => True, Value => 3);
   Integer_Value := Optional_Integer'(Defined => False);
end Option;

The last assignment will raise Constraint_Error.

I can't find the paragraph(s) in the ARM, but it is burried there
somewhere.

- Mark Lorenzen



  reply	other threads:[~2003-10-13 21:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-12  4:05 strings and multidimensional arrays Andrew
2003-10-12  5:24 ` Andrew
2003-10-12  6:27   ` tmoran
2003-10-12 14:16   ` Robert I. Eachus
2003-10-12 19:34     ` Jeffrey Carter
2003-10-13  0:02       ` Robert I. Eachus
2003-10-13  3:14         ` Jeffrey Carter
2003-10-13 17:05           ` Robert I. Eachus
2003-10-13 18:49             ` Martin Dowie
2003-10-13 21:47               ` Mark Lorenzen [this message]
2003-10-14  1:10             ` Jeffrey Carter
2003-10-14 15:29               ` Robert I. Eachus
2003-10-12 21:01     ` Andrew
2003-10-13 13:59 ` Rodrigo Garcia
  -- strict thread matches above, loose matches on Subject: below --
2003-10-14  6:24 christoph.grein
replies disabled

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