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 PROTECTED]
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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]

Reply via email to