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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2aaba1527862ef22 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!130.59.10.21.MISMATCH!kanaga.switch.ch!news-zh.switch.ch!switch.ch!cernne03.cern.ch!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Reading Float Data from a binary file into ada Date: Wed, 31 Jan 2007 09:42:48 +0100 Organization: CERN News Message-ID: References: <1170172307.292500.256090@m58g2000cwm.googlegroups.com> NNTP-Posting-Host: abpc10883.cern.ch Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: cernne03.cern.ch 1170232968 21567 137.138.37.241 (31 Jan 2007 08:42:48 GMT) X-Complaints-To: news@@cern.ch NNTP-Posting-Date: Wed, 31 Jan 2007 08:42:48 +0000 (UTC) User-Agent: Thunderbird 1.5.0.9 (X11/20061220) In-Reply-To: Xref: g2news2.google.com comp.lang.ada:8760 Date: 2007-01-31T09:42:48+01:00 List-Id: 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/