• 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: How do I get NSRect to be the same as CGRect?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I get NSRect to be the same as CGRect?


  • Subject: Re: How do I get NSRect to be the same as CGRect?
  • From: Rick Mann <email@hidden>
  • Date: Sun, 16 Dec 2007 16:56:22 -0800


On Dec 16, 2007, at 4:29 PM, Clark Cox wrote:

Before Leopard, NSRect and CGRect were completely different types.
Apple took the opportunity provided by the transition to 64-bit to
eliminate the discrepancy. But this change could break binary
compatibility, so it couldn't be done across the board for 32-bit
code.

Really? NSGeometry.h defines NSRect like this (in the non-64-bit case):

typedef struct _NSPoint {
    CGFloat x;
    CGFloat y;
} NSPoint;

typedef struct _NSSize {
    CGFloat width;		/* should never be negative */
    CGFloat height;		/* should never be negative */
} NSSize;


typedef struct _NSRect { NSPoint origin; NSSize size; } NSRect;



And CGGeometry.h defines CGRect like this:

struct CGPoint {
    CGFloat x;
    CGFloat y;
};
typedef struct CGPoint CGPoint;

/* Sizes. */

struct CGSize {
    CGFloat width;
    CGFloat height;
};
typedef struct CGSize CGSize;


struct CGRect { CGPoint origin; CGSize size; }; typedef struct CGRect CGRect;



Which seem to have identical layouts to me; that is, there should be no binary incompatibility. Furthermore, how could 32-bit portions of the API know if client code had defined it one way or another?

In my own case, I did an ugly cast from NSRect to CGRect so that my existing C++ code could go ahead and draw. It seems to work fine.

However, what I'd really like is for here to be a definition of NSRect that could be parsed by the C++ compiler (not having any Obj-C in it) so that my pre-existing Rect class could be made to easily be initialized from an NSRect.

Yes, just define NS_BUILD_32_LIKE_64. This was the first link on
Google when searching for "NS_BUILD_32_LIKE_64":

<http://developer.apple.com/documentation/Cocoa/Conceptual/Cocoa64BitGuide/64BitChangesCocoa/chapter_3_section_3.html >

I'm not really going for a 64-bit app here, and I understand there's some penalty for making an app 64-bit if you don't need it.


--
Rick

_______________________________________________

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


  • Follow-Ups:
    • Re: How do I get NSRect to be the same as CGRect?
      • From: "Sean McBride" <email@hidden>
    • Re: How do I get NSRect to be the same as CGRect?
      • From: "Clark Cox" <email@hidden>
References: 
 >How do I get NSRect to be the same as CGRect? (From: Rick Mann <email@hidden>)
 >Re: How do I get NSRect to be the same as CGRect? (From: "Clark Cox" <email@hidden>)

  • Prev by Date: Re: How do I get NSRect to be the same as CGRect?
  • Next by Date: Re: CurrencyConverter Bindings tutorial skips steps?
  • Previous by thread: Re: How do I get NSRect to be the same as CGRect?
  • Next by thread: Re: How do I get NSRect to be the same as CGRect?
  • Index(es):
    • Date
    • Thread