Re: structs in Mutable containers
Re: structs in Mutable containers
- Subject: Re: structs in Mutable containers
- From: "Sean McBride" <email@hidden>
- Date: Tue, 16 Sep 2008 13:50:33 -0400
- Organization: Rogue Research
On 9/16/08 10:22 AM, Clark Cox said:
>> This is what I was remembering:
>> <http://www.cellperformance.com/mike_acton/2006/06/
>> understanding_strict_aliasing.html#introduction>
>
>OK, examples that don't involve type-punned pointers:
> *SNIP*
So... I think I have it now:
- casting NSPoint to/from CGPoint is safe (with their current declarations).
- casting NSPoint* to/from CGPoint* is not, due to strict aliasing rules.
- NSPointToCGPoint exists incase their declarations one day diverge.
Interestingly Xcode's built-in docs show it as being implemented as:
CGPoint NSPointToCGPoint(NSPoint nspoint) {
return (*(CGPoint *)&(nspoint));
}
which seems to be unsafe, as they are breaking strict aliasing rules.
In NSGeometry.h it is actually implemented like so:
NS_INLINE CGPoint NSPointToCGPoint(NSPoint nspoint) {
union _ {NSPoint ns; CGPoint cg;};
return ((union _ *)&nspoint)->cg;
}
--
____________________________________________________________
Sean McBride, B. Eng email@hidden
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
_______________________________________________
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