From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.0 required=3.0 tests=BAYES_20 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 14 Sep 93 21:06:41 GMT From: sparky!steves@uunet.uu.net (Steve Scheuber) Subject: Checking byte order using unchecked_conversion Message-ID: <1993Sep14.210641.17606@sparky.sterling.com> List-Id: I'm posting this for a co-worker. Please respond via e-mail. Thank you. ----------- I would like to know if the following code reliably detects byte order using Unchecked_Conversion. (I don't have access to a big-endian machine.) This correctly detected byte order on a DEC VAX using ACS Ada. with System, Text_IO, Unchecked_Conversion; procedure Byte_Order is Byte : constant := System.Storage_Unit; Short_Int : constant := 2*Byte; type Bit8 is range 0 .. 2**Byte - 1; for Bit8'Size use Byte; type Bit16 is range 0 .. 2**Short_Int - 1; for Bit16'Size use Short_Int; type Bit16_Array is array(1..2) of Bit8; for Bit16_Array'Size use Short_Int; function Map is new Unchecked_Conversion(Source => Bit16, Target => Bit16_Array); The_Bit16 : constant Bit16 := 1; Mapped_Bit16 : constant Bit16_Array := Map(The_Bit16); begin if Mapped_Bit16'First = 1 then Text_IO.Put_Line("Low byte order"); elsif Text_IO.Put_Line("High byte order"); end if; end Byte_Order; -- Steve Scheuber NCYC Lives! Software Engineering Process Group INTERNET: steve_scheuber@sterling.com Sterling Software, ITD UUCP: sparky!steve_scheuber 1404 Ft. Crook Rd. South Phone: (402) 291-8300 Bellevue, NE. 68005-2969 FAX: (402) 291-4362