Mail Archives: djgpp/2000/02/24/23:00:22
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?
>
>I've seen them on every Unix box I had access to.
I have no doubt on what you are saying. But in the context of the
original problem, there seems to be the need, to be able to access
the exact same floating point values on different platforms. If this
is true, the portability to IEEE compatible floating point platforms
may be more important, than the portability to Unix platforms.
>> Also, one other problem might arise when
>> unsigned long is 64bit (i.e. Alpha, which uses IEEE floating point).
>
>I don't have access to an Alpha to check. Anybody?
Right now, I do not have access to an Alpha either. But I can
guarantee, that there was a mode, where unsigned long was 64 bit,
when I last used this platform (I cannot remember, whether 64 bit
unisgned long was the default. It may have needed some special
compiler switches.)
>I don't know. In general, I usually advise to stay away of passing FP
>numbers between different machines.
Yes, the most portable way to transform floating point values between
different platforms pobably is printf vs scanf/atof/strtod.
- Raw text -