Cocoa string to carbon compatible C string
Cocoa string to carbon compatible C string
- Subject: Cocoa string to carbon compatible C string
- From: Steve Cronin <email@hidden>
- Date: Sun, 11 May 2008 12:36:15 -0500
Folks;
I'm an ObjC guy who has to deal with some Carbon code that looks like
this:
#define kVERSION "abc"
#define kPARTNUMBER "123"
...
if ( (p_flag = initSomeSystem (
kVERSION,
kPARTNUMBER,
&errorCode))
== NULL) { ....
What I have to do is makethe kPARTNUMBER a value that is settable by
the user.
No problem collecting the data into NSString *partNumber.
So here's what I've done:
#define kVERSION "abc"
NSString * partNumber = [[blah blah] moreBlah];
.....
const char * cPartNumber = [partNumber
cStringUsingEncoding:NSUTF8StringEncoding];
if( (p_flag = initSomeSystem (
kVERSION,
(char *) cPartNumber,
&errorCode))
== NULL) { ....
Is this correct?
Is there a better way?
When you use a directive like #define x "abc" -> there is an implicit
definition of x as a 'char *', is that correct?
Thanks for adding any clarity,
Steve
_______________________________________________
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