Mail Archives: djgpp/2000/02/25/09:44:33
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
- Raw text -