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

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


  • Follow-Ups:
    • Re: Cocoa string to carbon compatible C string
      • From: Scott Ribe <email@hidden>
    • Re: Cocoa string to carbon compatible C string
      • From: Jens Alfke <email@hidden>
    • Re: Cocoa string to carbon compatible C string
      • From: Nick Zitzmann <email@hidden>
  • Prev by Date: Update slider position
  • Next by Date: Re: Cocoa string to carbon compatible C string
  • Previous by thread: Re: Update slider position
  • Next by thread: Re: Cocoa string to carbon compatible C string
  • Index(es):
    • Date
    • Thread