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!wns14feed!worldnet.att.net!attbi_s22.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Reading Float Data from a binary file into ada References: <1170172307.292500.256090@m58g2000cwm.googlegroups.com> <1170252776.235803.122220@j27g2000cwj.googlegroups.com> <1170268699.548152.214890@q2g2000cwa.googlegroups.com> In-Reply-To: <1170268699.548152.214890@q2g2000cwa.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <79awh.1166103$084.323259@attbi_s22> NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s22 1170288323 12.201.97.213 (Thu, 01 Feb 2007 00:05:23 GMT) NNTP-Posting-Date: Thu, 01 Feb 2007 00:05:23 GMT Organization: AT&T ASP.att.net Date: Thu, 01 Feb 2007 00:05:23 GMT Xref: g2news2.google.com comp.lang.ada:8800 Date: 2007-02-01T00:05:23+00:00 List-Id: frikk wrote: > > So my main question at this point is: How do I create the equivelant > of this: > union float_union > { > float x; > unsigned char c[4]; > }; That's pretty simple. You put your input bytes into subtype Raw_Bytes is System.Storage_Elements.Storage_Array (1 .. 4); Raw : constant Raw_Bytes := Reorder (Get_Bytes (Raw_Bytes'Length) ); (Raw is in the proper order, of course). You define function To_Float is new Ada.Unchecked_Conversion (Source => Raw_Bytes, Target => Interfaces.C.C_Float); and then Result : constant Interfaces.C.C_Float := To_Float (Raw); You probably want that in some application-friendly type, though, so you'd really do something like Result : constant My_Type := My_Type (To_Float (Raw) ); Finally return Result; This can end up being one of those functions where everything's done in the declarations. -- Jeff Carter "Alms for an ex-leper!" Monty Python's Life of Brian 75