Skip navigation.
 
mlCocoa string to carbon compatible C string
FROM : Steve Cronin
DATE : Sun May 11 19:36:15 2008

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

Related mailsAuthorDate
mlCocoa string to carbon compatible C string Steve Cronin May 11, 19:36
mlRe: Cocoa string to carbon compatible C string Nick Zitzmann May 11, 19:59
mlRe: Cocoa string to carbon compatible C string Jens Alfke May 11, 22:38
mlRe: Cocoa string to carbon compatible C string Steve Cronin May 12, 00:11
mlRe: Cocoa string to carbon compatible C string Nick Zitzmann May 12, 00:14
mlRe: Cocoa string to carbon compatible C string Scott Ribe May 12, 19:41