From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.36.84.210 with SMTP id t201mr3158927ita.35.1517744307608; Sun, 04 Feb 2018 03:38:27 -0800 (PST) X-Received: by 10.157.87.93 with SMTP id x29mr1345384oti.8.1517744307444; Sun, 04 Feb 2018 03:38:27 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.linkpendium.com!news.linkpendium.com!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!o66no53134ita.0!news-out.google.com!k194ni4991itb.0!nntp.google.com!o66no53133ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 4 Feb 2018 03:38:27 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=87.116.179.50; posting-account=z-xFXQkAAABpEOAnT3LViyFXc8dmoW_p NNTP-Posting-Host: 87.116.179.50 References: <43d8882f-04ee-46fa-8b71-43dbe512c604@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <2ee159e3-7fbd-4e4e-b056-85a0d2eea13e@googlegroups.com> Subject: Re: Array of records with default values not propagating to array From: Bojan Bozovic Injection-Date: Sun, 04 Feb 2018 11:38:27 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:50301 Date: 2018-02-04T03:38:27-08:00 List-Id: 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. >=20 > This is just a rule in Ada: in a record aggregate, one has to specify=20 > values for all the "needed components", whether or not the record type=20 > declaration supplies default values for some components. >=20 > This is different from a subprogram call, in which one can omit the=20 > parameter associations for parameters that have a default value. >=20 > The default values of record components are used in two cases: when one= =20 > creates an object of the type, without giving an initial value, such as= =20 > (in your code): >=20 > Temporary_Data : Card_Info; >=20 > Here, the default values in the Card_Info declaration come into play,=20 > and define the initial values of those components of Temporary_Data. >=20 > Here it means that Temporary_Data.Trump is False, and Name and=20 > Divinatory_Meaning are null unbounded strings. The component=20 > Temporary_Data.Trump_Value has an undefined value, as it is not given=20 > any default value in the declaration of Card_Info. >=20 > However, in your code, defining explicit default values of=20 > Null_Unbounded_String for the components Name and Divinatory_Meaning is= =20 > unnecessary, because every object of type Unbounded_String is=20 > initialised, by default, to Null_Unbounded_String. >=20 > The second case where default values of record components are used is in= =20 > a record aggreggate where a component association says " ... =3D> <>".=20 > Here, the "<>" means "use the default value, if there is one". >=20 > So, in your code, if a record aggregate for a Card_Info record says "...= =20 > =3D> <>" for the components Name and Divinatory_Meaning, it means that=20 > these components will be given the value Null_Unbounded_String. >=20 > >> When I omit "others =3D>" 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? >=20 > It is intended behaviour. The relevant Reference Manual rule is=20 > http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-4-3-1.html#p16 . >=20 > > The compiler does compile assignment of others =3D> <> to uninitialized > > record components as Mr. Simon Wright noticed above, >=20 > Why do you believe that the components (Name and Divinatory_Meaning) are= =20 > uninitialised? In my tests of the code, they are initialised, as=20 > expected, to Null_Unbounded_String. >=20 > > I have reproduced the bug both with GNAT 2017 GPL and FSF GNAT on > > Cygwin (6.4.0). >=20 > So far, I don't think there is any bug. >=20 > --=20 > 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 shou= ldn't have been assigned by others =3D> <> 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. = ;)