From: pavenis AT lanet DOT lv Message-ID: To: djgpp AT delorie DOT com, Dieter Buerssner Date: Fri, 25 Feb 2000 16:14:56 +0200 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: binary to float References: <200002241539 DOT RAA16262 AT is DOT elta DOT co DOT il> In-reply-to: X-mailer: Pegasus Mail for Win32 (v3.12b) Reply-To: djgpp AT delorie DOT com On 24 Feb 00, at 18:45, Eli Zaretskii wrote: > > On Thu, 24 Feb 2000, Dieter Buerssner wrote: > > > unsigned long l; > > float x; > > fread(&l, sizeof l, 1, fp); > > l = ntohl(l); > > x = *(float *)&l; > > > > My question, is this really more portable? In the libc info for ntohl > > under Portability I read: not ANSI, not POSIX. Is this function > > generally available? > This my not work with -fstrict-aliasing (default for gcc-2.95, gcc-2.95.1, and perhaps future released of gcc, but not gcc-2.95.2). In this case I suggest to use union union { long l; float x; } X; fread(&X.l sizeof(X.l), 1, fp); X.l = ntohl(X.l); An exception: pointer to char (or unsigned char) can alias anything Andris