From: Bojan Bozovic <bozovic.bojan@gmail.com>
Subject: Re: Array of records with default values not propagating to array
Date: Sun, 4 Feb 2018 03:38:27 -0800 (PST)
Date: 2018-02-04T03:38:27-08:00 [thread overview]
Message-ID: <2ee159e3-7fbd-4e4e-b056-85a0d2eea13e@googlegroups.com> (raw)
In-Reply-To: <fdo4acF3hi8U1@mid.individual.net>
On Sunday, February 4, 2018 at 11:07:10 AM UTC+1, Niklas Holsti wrote:
> On 18-02-04 06:59 , Bojan Bozovic wrote:
> > On Saturday, February 3, 2018 at 12:06:52 PM UTC+1, Bojan Bozovic wrote:
> >> When I defined a record, and set a default value for some of its
> >> components, these don't propagate when I make array of these
> >> records. Here is code that can be compiled, but I wonder do I
> >> need to explicitly assign value for 'others' in 'Initialize'
> >> procedure.
>
> This is just a rule in Ada: in a record aggregate, one has to specify
> values for all the "needed components", whether or not the record type
> declaration supplies default values for some components.
>
> This is different from a subprogram call, in which one can omit the
> parameter associations for parameters that have a default value.
>
> The default values of record components are used in two cases: when one
> creates an object of the type, without giving an initial value, such as
> (in your code):
>
> Temporary_Data : Card_Info;
>
> Here, the default values in the Card_Info declaration come into play,
> and define the initial values of those components of Temporary_Data.
>
> Here it means that Temporary_Data.Trump is False, and Name and
> Divinatory_Meaning are null unbounded strings. The component
> Temporary_Data.Trump_Value has an undefined value, as it is not given
> any default value in the declaration of Card_Info.
>
> However, in your code, defining explicit default values of
> Null_Unbounded_String for the components Name and Divinatory_Meaning is
> unnecessary, because every object of type Unbounded_String is
> initialised, by default, to Null_Unbounded_String.
>
> The second case where default values of record components are used is in
> a record aggreggate where a component association says " ... => <>".
> Here, the "<>" means "use the default value, if there is one".
>
> So, in your code, if a record aggregate for a Card_Info record says "...
> => <>" for the components Name and Divinatory_Meaning, it means that
> these components will be given the value Null_Unbounded_String.
>
> >> When I omit "others =>" in Initialize, I get compilation errors
> >> at these lines both on FSF compiler and AdaCore GPL compiler on
> >> Windows. Is this intended behavior or I am missing something?
>
> It is intended behaviour. The relevant Reference Manual rule is
> http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-4-3-1.html#p16 .
>
> > The compiler does compile assignment of others => <> to uninitialized
> > record components as Mr. Simon Wright noticed above,
>
> Why do you believe that the components (Name and Divinatory_Meaning) are
> uninitialised? In my tests of the code, they are initialised, as
> expected, to Null_Unbounded_String.
>
> > I have reproduced the bug both with GNAT 2017 GPL and FSF GNAT on
> > Cygwin (6.4.0).
>
> So far, I don't think there is any bug.
>
> --
> Niklas Holsti
> Tidorum Ltd
> niklas holsti tidorum fi
> . @ .
When in record declaration making components uninitialized like:
Name : Ada.Strings.Unbounded.Unbounded_String;
I had made a mistake to believe these had no proper initialization and shouldn't have been assigned by others => <> in assignment during Initialize, but explicitly, as Simon Wright originally said. I don't know enough about the language itself to discern if something isn't implemented correctly by the compiler, but it is, as Simon Wright rectified his stance on this, so I just sent some spam to AdaCore about that, but I don't think it matters. ;)
next prev parent reply other threads:[~2018-02-04 11:38 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
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 [this message]
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