comp.lang.ada
 help / color / mirror / Atom feed
From: bbarker@ball.com (Brian Barker)
Subject: Byte Swapping Constrained Data Types
Date: 20 Oct 2003 09:52:28 -0700
Date: 2003-10-20T09:52:28-07:00	[thread overview]
Message-ID: <e84604eb.0310200852.47a4a3e8@posting.google.com> (raw)

ObjectAda for Windows 7.2.2 Native
 
This is more of an Ada specific question if someone could help me.
 
I have declared an enumerated type like so:
 
     type Terminal is ( Null_Terminal, Primary, Secondary, Console  );
 
     for Terminal use
         ( Null_Terminal => 0,
           Primary    => 1,
           Secondary  => 2,
           Console      => 3);
 
     for Terminal'Size use 32;
 
 
I also have created a procedure based off of a generic byte-swap
routine:
 
     procedure Swap is new Endian.Generic_Swap(Terminal);
 
I receive a record over TCP/IP and it is in Big Endian format, so I
must byte swap it.  I have already copied the raw network data into my
structure that contains the Terminal type.  When I try to byte swap it
I receive a constraint error, because the big endian value of Terminal
is out of range.
 
     Swap(My_Record.Sending_Terminal); -- <- Sending_Terminal is of
type Terminal
 
I want to keep the generic swap, because I have so many abstract data
types.  I just want to get around this constraint range check when I
try to pass the value into the swap routine.  Does anyone have a
better suggestion?



             reply	other threads:[~2003-10-20 16:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-20 16:52 Brian Barker [this message]
2003-10-21  1:00 ` Byte Swapping Constrained Data Types Jeffrey Carter
  -- strict thread matches above, loose matches on Subject: below --
2003-10-20 18:25 Beard, Frank Randolph CIV
2003-10-20 19:21 ` Brian Barker
2003-10-20 21:01 Beard, Frank Randolph CIV
replies disabled

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