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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:ac8:6703:: with SMTP id e3-v6mr15128742qtp.62.1533148537406; Wed, 01 Aug 2018 11:35:37 -0700 (PDT) X-Received: by 2002:aca:4787:: with SMTP id u129-v6mr108779oia.4.1533148537239; Wed, 01 Aug 2018 11:35:37 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.swapon.de!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!e8-v6no2388813qtp.0!news-out.google.com!g23-v6ni514qtp.0!nntp.google.com!g24-v6no44340iti.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 1 Aug 2018 11:35:36 -0700 (PDT) In-Reply-To: <6cfb0a23-91d0-4ebe-9291-426280e12913@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=76.113.16.86; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 76.113.16.86 References: <6cfb0a23-91d0-4ebe-9291-426280e12913@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <2289a8c3-043f-4270-9c16-78a91f0bb2bf@googlegroups.com> Subject: Re: Variant record memory storage question From: Shark8 Injection-Date: Wed, 01 Aug 2018 18:35:37 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:54009 Date: 2018-08-01T11:35:36-07:00 List-Id: 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 i= t act almost like a C union allocating the memory for Variant_Record( Is_Bi= g ) even though it will never morph at run-time? >=20 > I am trying to determine the most memory-efficient way to store a complex= 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. The standard allows for it to be stored as 1-byte, as you desire, but does = not require this behavior. Since you are using GCC, I can tell you that it = uses the second behavior: because GCC / GNAT views compatibility with C as = a very high priority, and also because it's easier to do it that way. Dmitry, Randy, and/or Simon can probably give you more. (And might have a s= olution for you.)