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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2cbdd8de64214fc X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews2.google.com!not-for-mail From: ganesh.ramasivan@gdcanada.com (Ganesh Ramasivan) Newsgroups: comp.lang.ada Subject: Re: Variant Record Sizes.. Date: 20 Aug 2004 07:09:28 -0700 Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 209.29.50.252 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1093010968 5767 127.0.0.1 (20 Aug 2004 14:09:28 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 20 Aug 2004 14:09:28 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:2891 Date: 2004-08-20T07:09:28-07:00 List-Id: Thanks a lot for all your suggestions. I found that the result is compiler dependent. On the GNAT compiler, the size of Test_Record is 2 bytes but on the Greenhills Ada compiler, the result is 4 bytes. On consulting with Greenhills, they mention the following: "The size of the record includes the size of the largest variant part". This would confirm the results I am getting with the GHS compiler. Cheers!! Ganesh "Martin Dowie" wrote in message news:... > Ganesh Ramasivan wrote: > > Hello, > > > > I am having a hard time understanding variant records with regard to > > memory usage. Does the size of the record become the size of the > > largest element in that record? > > > > So in case of the example below, is the size of the Test_Record 2 > > bytes, even though the "use 8" clause has been specified as the other > > element of the record specifies "use 16". > > > > Any input will be appreciated. > > Couple of things: > Test_Record : TEST_ICP_POI_MESSAGE_TYPE(STATE_1); > > Constrains "Test_Record" to always be a subtype of TEST_ICP_POI_MESSAGE_TYPE > constrained to "STATE_1". > > Because you didn't supply a default value to the descriminant you can never > change which variant you want Test_Record to be: > > Both these things mean that the compile 'knows' that Test_Record need only > be 2 bytes long. > > So, > > 1) Add a default to the descriminant if you every what to change which > variant you want the variable to take; and > 2) Don't constrain the variable at declaration time. > > Cheers > > -- Martin