TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Stephen Leake <[log in to unmask]>
Reply To:
Stephen Leake <[log in to unmask]>
Date:
Wed, 6 Dec 2000 09:30:47 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (43 lines)
"David C. Hoos, Sr." <[log in to unmask]> pointed out that the
comments in the Endianness package I posted yesterday produce illegal
code. That's what I get for using comments, instead of real code :).

Here's a package with better comments; this time from real code

-- Abstract :
--
-- Define constants to reflect hardware bit and word endianness in record
-- representation clauses. Obviously, this file is highly system-dependent.
with System;
package Endianness is
   pragma Pure;

   -- this is for ObjectAda on an Intel 386 compatible processor
   System_Name : constant System.NAME := System.I80386;

   Endianness_Error : exception;

   Bit_Order      : constant := 1; -- 1 or -1
   High_Bit_First : constant := 0; -- 0 or 1
   Low_Bit_First  : constant := 1; -- opposite of High_Bit_First
   LSBit          : constant := 0; -- 0 or 7 or 15 (for word machines)

   -- typical usage of these constants, to make record spec independent of
   -- bit-endianness:
   --
   --    for Foo_Type use record
   --       User_Ephemeris_Needed       at 0 range LSBit + Bit_Order * 0 .. LSBit + Bit_Order * 0;
   --
   --       Operational_Status          at 0 range
   --          Low_Bit_First  * (LSBit + Bit_Order * 4) + High_Bit_First * (LSBit + Bit_Order * 7) ..
   --          High_Bit_First * (LSBit + Bit_Order * 4) + Low_Bit_First  * (LSBit + Bit_Order * 7);
   --    end record;

   type Byte_Order_Type is (BIG_ENDIAN, LITTLE_ENDIAN);
   Byte_Order : constant Byte_Order_Type := LITTLE_ENDIAN;

end Endianness;

--
-- Stephe

ATOM RSS1 RSS2