Re: Reading Float Data from a binary file into ada
- From: Maciej Sobczak <no.spam@xxxxxxxxxxx>
- Date: Wed, 31 Jan 2007 09:42:48 +0100
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/
.
- References:
- Reading Float Data from a binary file into ada
- From: frikk
- Re: Reading Float Data from a binary file into ada
- From: Steve
- Reading Float Data from a binary file into ada
- Prev by Date: Re: Ravenscar - program termination
- Next by Date: Re: Ravenscar - program termination
- Previous by thread: Re: Reading Float Data from a binary file into ada
- Next by thread: Re: Reading Float Data from a binary file into ada
- Index(es):