Sean, time ago I wrote and used this routine to "read" a float on a PPC.
But, as I understand, it will never work to "write" the file.
Any idea?
float ConvertEndianf(float infloat)
{
#ifdef __LITTLE_ENDIAN__
return infloat;
#else
union floatunion { unsigned char part[4]; float float_value; }
Converter;
char swap_char;
Converter.float_value = infloat;
swap_char = Converter.part[0];
Converter.part[0] = Converter.part[3];
Converter.part[3] = swap_char;
swap_char = Converter.part[1];
Converter.part[1] = Converter.part[2];
Converter.part[2] = swap_char;
return Converter.float_value;
#endif
}
> Da: Sean McBride <[email protected]>
> Organizzazione: Rogue Research Inc.
> Data: Fri, 30 Oct 2009 13:51:18 -0400
> A: "gMail.com" <[email protected]>, <[email protected]>
> Cc: Jens Alfke <[email protected]>
> Oggetto: Re: EndianU32_NtoB
>
> On 10/30/09 6:29 PM, gMail.com said:
>
>> Cool. Thanks. I did the following, either when I read from the disk and when
>> I write to the disk
>>
>> Read unsigned int in case of PPC
>> outValue[i] = EndianU32_NtoB(inValue[i]);
>>
>> Write unsigned int in case of PPC
>> outValue[i] = EndianU32_BtoN(inValue[i]);
>>
>> Read float in case of PPC
>> EndianDouble_NtoB(outValue[i], inValue[i]);
>>
>> Write float in case of PPC
>> EndianDouble_BtoN(outValue[i], inValue[i]);
>
> That's fine.
>
>> #define EndianDouble_BtoN(o,i)
>> ((Float64*)&o)[0]=CFConvertFloat64SwappedToHost(((CFSwappedFloat64*)&i)[0]);
>>
>> #define EndianDouble_NtoB(o,i)
>> ((CFSwappedFloat64*)&o)[0]=CFConvertFloat64HostToSwapped(((Float64*)&i)[0]);
>
> Not sure about that. I think you might be breaking 'struct aliasing
> rules'. What happens if you add the -Wstrict-aliasing warning flag?
> That's why I suggested using a union. See also:
> <http://cellperformance.beyond3d.com/articles/2006/06/understanding-
> strict-aliasing.html>
>
> --
> ____________________________________________________________
> Sean McBride, B. Eng [email protected]
> Rogue Research www.rogue-research.com
> Mac Software Developer Montréal, Québec, Canada
>
>
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]