From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Advent of Code Day 7
Date: Mon, 7 Dec 2020 17:44:44 -0600 [thread overview]
Message-ID: <rqmepd$1q2$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: df3d282a-ff8c-4fd7-befc-a6ca683215e1n@googlegroups.com
"John Perry" <john.perry@usm.edu> wrote in message
news:df3d282a-ff8c-4fd7-befc-a6ca683215e1n@googlegroups.com...
> When doing today's exercise, I encountered an issue where I wanted to
> initialize only some fields of a record, with the other fields having a
> default initialization. In particular:
>
> type Bag_Entry is record
> Description: Bag_Description := " ";
> Quantity: Positive;
> end record;
>
> Entry: Bag_Entry := ( Quantity => 10 );
>
> However, GNAT says this is invalid because I didn't specify
> Bag_Description. I looked in the ARM but didn't see anyplace that implies
> that; did I miss it? Is there a reason that Description can't be
> initialized automatically according to the rules above?
In Ada 2005 and later, write:
Entry: Bag_Entry := (Quantity => 10, Description => <>);
In an aggregate, <> means a default initialized component. Following the Ada
Way TM ;-), one has to explicitly ask for a default initialized component --
just leaving it out might have been a mistake or intended -- neither the
compiler nor a reader can tell. The above is clearly intended.
Randy.
next prev parent reply other threads:[~2020-12-07 23:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-07 23:03 Advent of Code Day 7 John Perry
2020-12-07 23:44 ` Randy Brukardt [this message]
2020-12-07 23:49 ` John Perry
2020-12-08 11:25 ` Jeffrey R. Carter
2020-12-08 16:55 ` John Perry
2020-12-08 23:25 ` 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