comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <nholsti@icon.fi>
Subject: Re: Help needed in port to GNAT95 from verdix
Date: 1998/05/15
Date: 1998-05-15T00:00:00+00:00	[thread overview]
Message-ID: <355B6246.457F7282@icon.fi> (raw)
In-Reply-To: 6jcvoc$drd$1@plug.news.pipex.net


Paul Hussein wrote:
> 
> 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.

Using floats here is quite surprising, but perhaps you know what you
are doing... I would have used storage_units. Also, you might want to
check out the Ada 95 stream concept, with the 'Read and 'Write
services.

[ elided package spec ]

> 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 );

It seems quite likely that the exact size of the Source and Target
types will differ. Unchecked conversion between types of different
sizes is IMHO rather risky, from a portability point of view.
Same comment for the unchecked conversion in Packer.UnPack.

[ elided rest of Packer ]

> with Packer;
> with Text_IO;
> with Sim_Support;
> procedure Test is
 
[ elided a bit ]

>    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 );

According to my trial run, this tries to assign an array of
length 52 to an array of length 10000. Constraint error
is to be expected.

I cannot imagine how you got this to work under Verdix, except
by turning off constraint checks. The length of the Packed array
may have been different, due to a different lay-out of the "blob"
type under Verdix and GNAT, but the length must surely have been
less than 10000.

Do check out the streams and 'Read, 'Write. I think they are what
you need here.




      parent reply	other threads:[~1998-05-15  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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         ` Larry Kilgallen
1998-05-19  0:00           ` John McCabe
1998-05-15  0:00         ` Jean-Pierre Rosen
1998-05-16  0:00           ` Robert Dewar
1998-05-15  0:00 ` Niklas Holsti [this message]
replies disabled

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