comp.lang.ada
 help / color / mirror / Atom feed
* Checking byte order using unchecked_conversion
@ 1993-09-14 21:06 Steve Scheuber
  0 siblings, 0 replies; only message in thread
From: Steve Scheuber @ 1993-09-14 21:06 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1993-09-14 21:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-09-14 21:06 Checking byte order using unchecked_conversion Steve Scheuber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox