From: Maciej Sobczak <no.spam@no.spam.com>
Subject: Re: Reading Float Data from a binary file into ada
Date: Wed, 31 Jan 2007 09:42:48 +0100
Date: 2007-01-31T09:42:48+01:00 [thread overview]
Message-ID: <eppkq8$l1v$1@cernne03.cern.ch> (raw)
In-Reply-To: <kPOdnX7qRM9Rj13YnZ2dnUVZ_t-mnZ2d@comcast.com>
Steve wrote:
> The following snippet contains the pieces you need to do the conversion.
>
> TYPE aByte IS MOD 256;
>
> FOR aByte'SIZE USE 8;
>
> TYPE aByteArray IS ARRAY( Positive RANGE <> ) OF aByte;
>
> PRAGMA PACK( aByteArray );
>
> TYPE aFourBytes IS NEW aByteArray(1..4);
>
> FUNCTION Conv IS NEW Ada.Unchecked_Conversion( aFourBytes, float );
>
> ...
>
> a : float;
> b : aFourBytes;
>
> ...
>
> a := Conv( b )
>
> Use unchecked conversion to convert from a type that contains 4 bytes to the
> float value you're looking for.
You have typed lots of lines of code to ensure that 4 bytes are treated
as 4 bytes, but you did not provide any guarantee that Float has 4 bytes
as well. You *can* rely on some assumptions about your compiler, but
having these assumptions already in place anyway, is there a way to make
the conversion simpler? Cannot you just read four bytes from the file
directly to the Float variable using for example sequential or direct I/O?
--
Maciej Sobczak : http://www.msobczak.com/
Programming : http://www.msobczak.com/prog/
next prev parent reply other threads:[~2007-01-31 8:42 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-30 15:51 Reading Float Data from a binary file into ada frikk
2007-01-30 16:37 ` Dmitry A. Kazakov
2007-01-30 16:55 ` Jean-Pierre Rosen
2007-01-30 17:35 ` Ali Bendriss
2007-02-01 16:28 ` Ali Bendriss
2007-02-01 17:27 ` Jean-Pierre Rosen
2007-01-30 17:56 ` Jeffrey R. Carter
2007-01-30 18:04 ` frikk
2007-01-30 19:56 ` frikk
2007-01-31 18:30 ` Jeffrey R. Carter
2007-01-30 20:51 ` Robert A Duff
2007-01-31 18:25 ` Jeffrey R. Carter
2007-01-31 18:57 ` frikk
2007-01-30 19:31 ` Niklas Holsti
2007-01-30 21:14 ` Cesar Rabak
2007-01-30 21:36 ` frikk
2007-02-01 21:11 ` Simon Wright
2007-02-01 21:44 ` Niklas Holsti
2007-02-03 12:13 ` Simon Wright
2007-02-03 14:59 ` Gautier
2007-02-03 17:01 ` Simon Wright
2007-01-30 20:02 ` Martin Dowie
2007-01-30 20:09 ` frikk
2007-01-30 20:23 ` Martin Dowie
2007-01-31 3:54 ` Steve
2007-01-31 8:42 ` Maciej Sobczak [this message]
2007-01-31 14:12 ` frikk
2007-01-31 18:38 ` frikk
2007-02-01 0:05 ` Jeffrey R. Carter
2007-02-01 2:59 ` Steve
2007-02-01 16:05 ` Bob Spooner
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox