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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Array of records with default values not propagating to array Date: Sun, 4 Feb 2018 12:07:08 +0200 Organization: Tidorum Ltd Message-ID: References: <43d8882f-04ee-46fa-8b71-43dbe512c604@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net KY+zNEGIOzbdtMrm5wn/Uw+lk3cFogAyaYRFUmnUCkhonZvvzn Cancel-Lock: sha1:FGRCuiyTukUYLlEOC2wtIgo1xE0= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: <43d8882f-04ee-46fa-8b71-43dbe512c604@googlegroups.com> Xref: reader02.eternal-september.org comp.lang.ada:50299 Date: 2018-02-04T12:07:08+02:00 List-Id: 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 . @ .