Re: Cocoa string to carbon compatible C string
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