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,start 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: Variant Record Sizes.. Date: 19 Aug 2004 11:48:25 -0700 Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 209.29.50.252 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1092941335 15956 127.0.0.1 (19 Aug 2004 18:48:55 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 19 Aug 2004 18:48:55 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:2868 Date: 2004-08-19T11:48:25-07:00 List-Id: 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. Thanks, Ganesh ------------------------ with ada.text_io; procedure Variant is package int_io is new ada.text_io.integer_io(Integer); type TEST_STATE_CHOICE is (DISABLE, ENABLE); for TEST_STATE_CHOICE'SIZE use 8; type OTHER_STATE_CHOICE is (ON, OFF); for OTHER_STATE_CHOICE'SIZE use 16; type TEST_ICP_POI_MESSAGE_ID_CHOICE is (STATE_1, STATE_2); for TEST_ICP_POI_MESSAGE_ID_CHOICE'SIZE use 8; type TEST_ICP_POI_MESSAGE_TYPE (ICP_POI_MESSAGE_ID : TEST_ICP_POI_MESSAGE_ID_CHOICE) is record case ICP_POI_MESSAGE_ID is when STATE_1 => ICP_STATE : TEST_STATE_CHOICE; when STATE_2 => PING_STATE : OTHER_STATE_CHOICE; when others => null; end case; end record; pragma pack (TEST_ICP_POI_MESSAGE_TYPE); Test_Record : TEST_ICP_POI_MESSAGE_TYPE(STATE_1); Record_Size : INTEGER := 0; begin Record_Size := Test_Record'Size/8; ada.text_io.put("Record Size = "); int_io.put(Record_Size); ada.text_io.new_line; end Variant; --------------------------