comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Array of records with default values not propagating to array
Date: Sun, 04 Feb 2018 09:32:03 +0000
Date: 2018-02-04T09:32:03+00:00	[thread overview]
Message-ID: <ly7ertnlrg.fsf@pushface.org> (raw)
In-Reply-To: fdo1l1F2uchU1@mid.individual.net

Niklas Holsti <niklas.holsti@tidorum.invalid> writes:

> On 18-02-03 17:26 , Simon Wright wrote:
>
>> I find that
>>
>>    type Card_Info (Trump : Boolean := False) is record
>>       Name : Ada.Strings.Unbounded.Unbounded_String;
>>       Divinatory_Meaning : Ada.Strings.Unbounded.Unbounded_String;
>>       ...
>>
>>          TDeck (Index) :=
>>            (Trump       => True,
>>             Trump_Value => Index_1,
>>             others      => <>);
>>          ...
>>
>>             TDeck (Index) :=
>>               (Trump      => False,
>>                Card_Value => Card_Index,
>>                Suit_Value => Suit_Index,
>>                others     => <>);
>>
>> compiles OK and seems to run perfectly well. Presumably this is OK
>> because the initial value for an otherwise-uninitialized unbounded
>> string is the empty string. Or maybe it's GNAT being over-helpful, since
>> it seems not to obey ARM 4.3.1(17.1)[1].
>>
>> [1] http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-4-3-1.html#p17.1
>
> I don't think that ARM paragraph applies to the "others" in this
> code. The paragraph says:
>
> "A record_component_association for a discriminant without a
> default_expression shall have an expression rather than <>"
>
> but the components covered by the "others" in this code are not
> discriminants. The discriminant is the Trump component, and the
> associations for Trump have an expression (True or False), not <>.

Oh, yes.

I should have looked a bit further down: (19.1) says

   "... For a record_component_association with <>, if the
   component_declaration has a default_expression, that
   default_expression defines the value for the associated component(s);
   otherwise, the associated component(s) are initialized by default as
   for a stand-alone object of the component subtype (see 3.3.1)."

which is exactly what OP needs.


  reply	other threads:[~2018-02-04  9:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-03 11:06 Array of records with default values not propagating to array Bojan Bozovic
2018-02-03 14:16 ` Jere
2018-02-03 14:54   ` Bojan Bozovic
2018-02-03 15:26   ` Simon Wright
2018-02-03 16:07     ` Jere
2018-02-04  9:21     ` Niklas Holsti
2018-02-04  9:32       ` Simon Wright [this message]
2018-02-04  2:43 ` Robert Eachus
2018-02-04  4:59 ` Bojan Bozovic
2018-02-04  9:34   ` Simon Wright
2018-02-04 10:07   ` Niklas Holsti
2018-02-04 11:38     ` Bojan Bozovic
2018-02-04 10:19 ` Jeffrey R. 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