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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,cec65b0a3ccd802d X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: Big-endian vs little-endian Date: 1999/02/07 Message-ID: #1/1 X-Deja-AN: 441568439 Sender: matt@mheaney.ni.net References: <36B155D2.2E8573BB@wvu.edu> <7982p9$nll$3@plug.news.pipex.net> <36BB9A6E.D472A709@wvu.edu> NNTP-Posting-Date: Sat, 06 Feb 1999 21:08:41 PDT Newsgroups: comp.lang.ada Date: 1999-02-07T00:00:00+00:00 List-Id: Mike Werner writes: > Here's the relevant data structure: > > type Sys_type is (Zarya, Unity, PMA1, PMA2); > type Subsys_type is (CDH, CT, ECLSS, EPS, GNC, SM); > subtype Desc_type is String(1..256); > subtype Dur_Min_Type is Integer; > subtype Dur_Sec_type is Integer; > type Apm_Rec is > record > Description : Desc_Type; > System : Sys_Type; > Subsystem : Subsys_Type; > Dur_Min : Dur_Min_Type; > Dur_Sec : Dur_Sec_Type; > end record; > > The problematic parts were the Apm_Rec.Dur_Min and the Apm_Rec.Dur_Sec - > all the others read in just fine. If I'm understanding all this, should > I have changed > > subtype Dur_Min_Type is Integer; > subtype Dur_Sec_type is Integer; > > to > > subtype Dur_Min_Type is Integer(S'Bit_Order=>Low_Order_First); > subtype Dur_Sec_type is Integer(S'Bit_Order=>Low_Order_First); > > or perhaps High_Order_First - haven't got everything handy at the > moment. But the main question is do I have the right syntax and usage? > Or am I completely off here? Yes, you are completely off. Don't bother with the Bit_Order attribute. No compiler vendors support it. That leads us to this: type Sys_type is (Zarya, Unity, PMA1, PMA2); type Subsys_type is (CDH, CT, ECLSS, EPS, GNC, SM); type Apm_Rec is record Description : Desc_Type (1 .. 256); System : Sys_Type; Subsystem : Subsys_Type; Dur_Min : Integer range 0 .. 59; Dur_Sec : Integer range 0 .. 59; end record; There are two advantages to this: 1) we can pack the last four fields in one longword 2) the integer types fit in 1 byte, so we don't have to worry about byte-swapping I think you should now be able to write a standard rep clause for this record ("for Apm_Rec use ..."), that will work for both big- and little-endian machines. (Because the latter fields are 1 byte, and the representation of one-byte data on either machine is the same.) If you do decide to use 32-bit integers for Dur_Min and Dur_Sec, you still don't have a rep clause problem. But you do have a byte-swapping problem.