comp.lang.ada
 help / color / mirror / Atom feed
* Help needed in port to GNAT95 from verdix
@ 1998-05-13  0:00 Paul Hussein
  1998-05-14  0:00 ` Mats Weber
  1998-05-15  0:00 ` Niklas Holsti
  0 siblings, 2 replies; 10+ messages in thread
From: Paul Hussein @ 1998-05-13  0:00 UTC (permalink / raw)



I do not understand  why a piece of code that works on verdix will not now
work an gnat95, and this is an important piece of code. If anyone could help
it would be most appreciated.


When I run this code sample, and the code itself  in our system I get a
constraint error.
This code endeavours to turn any type into an array of floats for passing
over the network.



generic
   -- Type that is to be packed
   type Object_Type is private;
package Packer is
   type Packed_Object_Type is array ( POSITIVE range <> ) of FLOAT;
   --
   -- PURPOSE:
   -- Packs the object into the array of floats
   --
   function Pack   ( Object : in Object_Type ) return Packed_Object_Type;
   --
   -- PURPOSE:
   -- Unpacks the object from the array of floats
   --
   function UnPack ( Packed_Object : in Packed_Object_Type ) return
Object_Type;
end Packer;
--
-- Standard Packages
--
with UNCHECKED_CONVERSION;
package body Packer is
   --
   -- PURPOSE:
   -- Packs the object into the array of floats
   --
   function Pack ( Object : in Object_Type ) return Packed_Object_Type is
      Size_Of_Array : POSITIVE := Object_Type'size/FLOAT'size + 1;
      subtype Local_Packed_Object_Type is Packed_Object_Type ( 1 ..
Size_Of_Array );
      Packed_Object : Local_Packed_Object_Type;
      function To_Array is new UNCHECKED_CONVERSION
        ( Source => Object_Type,
          Target => Local_Packed_Object_Type );
   begin --Pack
      Packed_Object := To_Array ( Object );
      return Packed_Object;
   end Pack;
   --
   -- PURPOSE:
   -- Unpacks the object from the array of floats
   --
   function UnPack ( Packed_Object : in Packed_Object_Type ) return
Object_Type is
      Size_Of_Array : POSITIVE := Object_Type'size/FLOAT'size + 1;
      subtype Local_Packed_Object_Type is Packed_Object_Type ( 1 ..
Size_Of_Array );
      function To_Object is new UNCHECKED_CONVERSION
        ( Source => Local_Packed_Object_Type,
          Target => Object_Type );
   begin --UnPack
      return To_Object ( Packed_Object );
   end UnPack;
end Packer;

package Sim_Support is
   type Data_Array is array ( POSITIVE range <> ) of FLOAT;
end Sim_Support;

with Packer;
with Text_IO;
with Sim_Support;
procedure Test is
   type Affile is ( red, green );
   type strings is array ( 1.. 20 ) of STRING(1..10);
   type ar is array ( 1 .. 10 ) of integer;
   type blob ( switch : boolean := true ) is
      record
         case switch is
            when true =>
               a : Affile := Affile'first;
               b : ar;
            when false =>
               c : strings;
         end case; --switch
      end record;
   package p is new packer ( blob );
   procedure pack
      ( Data   : in blob;
        Floats : out Sim_Support.Data_Array ) is
   begin
      declare
         Packed : constant P.Packed_Object_Type :=
            P.Pack ( data );
      begin
         Floats := Sim_Support.Data_Array ( Packed );
      end;
   end;
   procedure unpack
      ( Data   : out blob;
        Floats : in Sim_Support.Data_Array ) is
   begin
      Data := P.UnPack ( P.Packed_Object_Type ( Floats ) );
   end;
   to_convert : blob;
   Floats     : Sim_Support.Data_Array ( 1 .. 10_000 );
begin --test
   text_io.put_line ( integer'image (blob'size) );
   text_io.put_line ( integer'image (Floats'size) );
   to_convert.a := green;
   for I in to_convert.b'range loop
      to_convert.b(I) := I;
   end loop;
   pack
      ( Data   => to_convert,
        Floats => Floats );
   unpack
      ( Data   => to_convert,
        Floats => Floats );
end test;














^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~1998-05-19  0:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-13  0:00 Help needed in port to GNAT95 from verdix Paul Hussein
1998-05-14  0:00 ` Mats Weber
1998-05-14  0:00   ` Charles Hixson
1998-05-14  0:00     ` Matthew Heaney
     [not found]     ` <Esyp0E.5q0@world.std.com>
1998-05-14  0:00       ` Robert Dewar
1998-05-15  0:00         ` Jean-Pierre Rosen
1998-05-16  0:00           ` Robert Dewar
1998-05-15  0:00         ` Larry Kilgallen
1998-05-19  0:00           ` John McCabe
1998-05-15  0:00 ` Niklas Holsti

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