• 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: Cocoa string to carbon compatible C string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa string to carbon compatible C string


  • Subject: Re: Cocoa string to carbon compatible C string
  • From: Jens Alfke <email@hidden>
  • Date: Sun, 11 May 2008 13:38:58 -0700


On 11 May '08, at 10:36 AM, Steve Cronin wrote:

const char * cPartNumber = [partNumber cStringUsingEncoding:NSUTF8StringEncoding];

That looks correct, assuming the Carbon function does take a C string in UTF-8 encoding, but you can make it a bit more compact:


	const char *  cPartNumber = [partNumber UTF8String];

(char *) cPartNumber,

It would be a good idea to check whether that function takes a char* (instead of const char*) because it actually writes back into the string, or because someone just forgot to put a "const" in its declaration. Most likely it's the latter, but in the former case there's a chance it could blow up the heap if it decides to overwrite the C string generated by the NSString.


—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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: 
 >Cocoa string to carbon compatible C string (From: Steve Cronin <email@hidden>)

  • Prev by Date: Problems with object observing own key
  • Next by Date: Re: Problems with object observing own key
  • Previous by thread: Re: Cocoa string to carbon compatible C string
  • Next by thread: Re: Cocoa string to carbon compatible C string
  • Index(es):
    • Date
    • Thread