From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2ceb82769e7e23b,start X-Google-Attributes: gid103376,public From: "Paul Hussein" Subject: Help needed in port to GNAT95 from verdix Date: 1998/05/13 Message-ID: <6jcvoc$drd$1@plug.news.pipex.net>#1/1 X-Deja-AN: 352981820 X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3 Organization: UUNET WorldCom server (post doesn't reflect views of UUNET WorldCom) Newsgroups: comp.lang.ada Date: 1998-05-13T00:00:00+00:00 List-Id: 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;