• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: structs in Mutable containers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >structs in Mutable containers (From: "Christian Giordano" <email@hidden>)
 >Re: structs in Mutable containers (From: Graham Cox <email@hidden>)
 >Re: structs in Mutable containers (From: "Sean McBride" <email@hidden>)
 >Re: structs in Mutable containers (From: "Clark Cox" <email@hidden>)
 >Re: structs in Mutable containers (From: "Sean McBride" <email@hidden>)
 >Re: structs in Mutable containers (From: "Clark Cox" <email@hidden>)

  • Prev by Date: Re: (Newb) Multiple NSWindowControllers and bindings
  • Next by Date: Core data "grand-children" list
  • Previous by thread: Re: structs in Mutable containers
  • Next by thread: How do I check if at least one TWAIN device is available
  • Index(es):
    • Date
    • Thread