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 X-Received: by 2002:ac8:538b:: with SMTP id x11-v6mr15536068qtp.15.1533149508621; Wed, 01 Aug 2018 11:51:48 -0700 (PDT) X-Received: by 2002:aca:c744:: with SMTP id x65-v6mr108979oif.2.1533149508442; Wed, 01 Aug 2018 11:51:48 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.uzoreto.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!e8-v6no2394956qtp.0!news-out.google.com!g23-v6ni514qtp.0!nntp.google.com!g24-v6no58272iti.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 1 Aug 2018 11:51:48 -0700 (PDT) In-Reply-To: <2289a8c3-043f-4270-9c16-78a91f0bb2bf@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=73.205.150.94; posting-account=Ru7E4QoAAAC_HiQ2D8LjZ7rh1mbTNcVn NNTP-Posting-Host: 73.205.150.94 References: <6cfb0a23-91d0-4ebe-9291-426280e12913@googlegroups.com> <2289a8c3-043f-4270-9c16-78a91f0bb2bf@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Variant record memory storage question From: NiGHTS Injection-Date: Wed, 01 Aug 2018 18:51:48 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:54010 Date: 2018-08-01T11:51:48-07:00 List-Id: On Wednesday, August 1, 2018 at 2:35:38 PM UTC-4, Shark8 wrote: > On Wednesday, August 1, 2018 at 11:38:06 AM UTC-6, NiGHTS wrote: > > Say I had a variant record like this: > >=20 > > type Which_One is (Is_Small, Is_Big); > >=20 > > type Variant_Record (Option : Which_One) is=20 > > record > > case Option is > > when Is_Small =3D> > > Var_1 : Byte -- 1 byte > > when Is_Big =3D> > > Var_2 : Some_Large_Record -- 1000 bytes > > end case; > > end record; > >=20 > > Will the record Variant_Record( Is_Small ) be stored as 1 byte? Or does= it act almost like a C union allocating the memory for Variant_Record( Is_= Big ) even though it will never morph at run-time? > >=20 > > I am trying to determine the most memory-efficient way to store a compl= ex record and it seems Variant_Record can help me do this, but I am unsure = if it will work the way I think it will. > >=20 > > Note I am using gcc. Thank you. >=20 > The standard allows for it to be stored as 1-byte, as you desire, but doe= s not require this behavior. Since you are using GCC, I can tell you that i= t uses the second behavior: because GCC / GNAT views compatibility with C a= s a very high priority, and also because it's easier to do it that way. >=20 > Dmitry, Randy, and/or Simon can probably give you more. (And might have a= solution for you.) Could I use a pragma to give the compiler an explicit request to store the = data in the smallest possible way? I would think the option should exist to= hint to the compiler that I don't care about C compatibility for this reco= rd.