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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,febd9e55846c9556 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-03-03 08:07:03 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!logbridge.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Endianness independance Date: 03 Mar 2003 11:05:14 -0500 Organization: NASA Goddard Space Flight Center (skates.gsfc.nasa.gov) Message-ID: References: <5115eb96.0303010248.1b2b8d37@posting.google.com> NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 1046708349 19578 128.183.235.92 (3 Mar 2003 16:19:09 GMT) X-Complaints-To: usenet@news.gsfc.nasa.gov NNTP-Posting-Date: 3 Mar 2003 16:19:09 GMT User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:34828 Date: 2003-03-03T16:19:09+00:00 List-Id: "Marin David Condic" writes: > Well, but if hardware is not standardized, then why would you expect > languages to be standardized? (With respect to data representations.) The point is that Ada provides a _standard_, _single_ representation clause that works for both kinds of hardware: -- Abstract : -- -- Define constants to reflect hardware bit and word endianness in -- record representation clauses. Obviously, this file is highly -- system-dependent. -- with System; package SAL.Endianness is pragma Pure; -- This is for gnat on a Mongoose processor System_Name : constant System.Name := System.SYSTEM_NAME_GNAT; type Byte_Order_Type is (Big_Endian, Little_Endian); Byte_Order : constant Byte_Order_Type := Big_Endian; -- The Mongoose documentation numbers bits with LSB = 0. However, -- the byte order is Big_Endian, so the Ada compiler assumes bits -- are numbered with MSB = 0, since that allows representation -- clauses with fields that cross natural boundaries. Bit_Order : constant := -1; -- 1 or -1 High_Bit_First : constant := 1; -- 0 or 1 Low_Bit_First : constant := 0; -- 1 or 0 -- Use one of these, corresponding to the natural size of the -- record you are laying out. LSBit_8 : constant := 7; -- 0 or 7 LSBit_16 : constant := 15; -- 0 or 15 LSBit_32 : constant := 31; -- 0 or 31 LSBit_56 : constant := 55; -- 0 or 55 end SAL.Endianness; package Foo is type B_Field_Control_Type is record -- [1] Table 4.2.8 Spare_1 : Interfaces_More.Unsigned_29; Data : Interfaces_More.Unsigned_3; end record; for B_Field_Control_Type use record Spare_1 at 0 range Low_Bit_First * (LSBit_32 + Bit_Order * 3) + High_Bit_First * (LSBit_32 + Bit_Order * 31) .. High_Bit_First * (LSBit_32 + Bit_Order * 3) + Low_Bit_First * (LSBit_32 + Bit_Order * 31); Data at 0 range Low_Bit_First * (LSBit_32 + Bit_Order * 0) + High_Bit_First * (LSBit_32 + Bit_Order * 2) .. High_Bit_First * (LSBit_32 + Bit_Order * 0) + Low_Bit_First * (LSBit_32 + Bit_Order * 2); end record; for B_Field_Control_Type'Size use 32; end foo; In C, you have to use the preprocessor to get this. In Ada, it would be nice if you could say: for B_Field_Control_Type'Bit_Order use Little_Bit_First; But you can't, because the compiler would have to know whether the data is "naturally" 32, 16, or 8 bit (that's what the "LSBit_32" is for above). -- -- Stephe