Re: "byte orders" question
Re: "byte orders" question
- Subject: Re: "byte orders" question
- From: Kyle Sluder <email@hidden>
- Date: Sat, 26 Nov 2011 16:23:47 -0800
On Sat, Nov 26, 2011 at 4:17 PM, Greg Guerin <email@hidden> wrote:
> Since you're just doing a memcpy(), you can simply cast the bits and avoid
> the copying. Try this:
>
> float f = *((float*) &res);
>
> Or try defining a C union:
>
> union foo { float f; u_int32_t u; };
> union foo bar;
> bar.u = CFSwapInt32HostToBig(value);
> float f = bar.f;
Neither of these is legal. You are not allowed to alias a pointer to
two different types (except pointer-to-char). See Section 6.5,
paragraph 7 of the C99 standard:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
--Kyle Sluder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden