Re: Cocoa string to carbon compatible C string

2008-05-12 Thread Scott Ribe
There's also the issue of the lifetime of the string. Will initSomeSystem hang on to the char * after the call returns? If so, your code will blow up since when the NSString goes it will take with it that C string--instead you'd have use one of the calls that *copies* the C string into a buffer

Cocoa string to carbon compatible C string

2008-05-11 Thread Steve Cronin
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,

Re: Cocoa string to carbon compatible C string

2008-05-11 Thread Nick Zitzmann
On May 11, 2008, at 11:36 AM, Steve Cronin wrote: Is this correct? Is there a better way? It depends. Does the code take a real C string (char array), or does it take an Str63 or Str255 or something? If the latter, then you need to use CoreFoundation to get a Pascal string from the

Re: Cocoa string to carbon compatible C string

2008-05-11 Thread Jens Alfke
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 *

Re: Cocoa string to carbon compatible C string

2008-05-11 Thread Steve Cronin
Nick; Thanks for the info, the deal is I don't have access to the source for 'initSomeSystem'. So I can't answer your question, other than to point out what does work.. I do know that ' #define kVersion abc ' creates a suitable string. I'm trying to do the 'best' substitution I can with

Re: Cocoa string to carbon compatible C string

2008-05-11 Thread Nick Zitzmann
On May 11, 2008, at 4:11 PM, Steve Cronin wrote: If that is true, then is the following the best solution? I guess it is then, unless initSomeSystem() modifies the character array, in which case you may have a problem. You could also use - UTF8String instead of -cStringUsingEncoding: if