• 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: convert CFRange to NSRange?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: convert CFRange to NSRange?


  • Subject: Re: convert CFRange to NSRange?
  • From: Andreas Grosam <email@hidden>
  • Date: Sun, 12 Dec 2010 17:51:20 +0100

On Dec 12, 2010, at 4:34 PM, Matt Neuburg wrote:

> I feel like I'm missing something. I can't seem to typecast as CFRange to an NSRange.

Both are distinct C structs. In C, *explicitly* typecasting one pointer to the other would be allowed but semantically incorrect. In C++ casting a pointer to the other would be illegal.

> I know I can pull a CFRange apart and reassemble it as an NSRange, but shouldn't there be a simpler way? m.

In fact, initializing a NSRange value from a CFRange value by means of a library function would not be as easy as it might look at the first glance. The reason is, CFRange has field members whose type is a *signed* long, and  NSRange field types are *unsigned* ints or *unsigned* longs (the size depending on architecture). Mixing signed and unsigned types - possibly with different bit-sizes - in a simple assignment operation would require overflow checks and may require to throw exceptions. So, what should a library function do?

If required, you can include these checks in your code, though.


Regards
Andreas

_______________________________________________

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: convert CFRange to NSRange?
      • From: John Engelhart <email@hidden>
References: 
 >convert CFRange to NSRange? (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Re: convert CFRange to NSRange?
  • Next by Date: Re: iOS multiple text colors in an editable text field
  • Previous by thread: Re: convert CFRange to NSRange?
  • Next by thread: Re: convert CFRange to NSRange?
  • Index(es):
    • Date
    • Thread