• 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
Re: What's the difference between a C++ and ObjC String?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's the difference between a C++ and ObjC String?


  • Subject: Re: What's the difference between a C++ and ObjC String?
  • From: "Frederick C. Lee" <email@hidden>
  • Date: Fri, 1 Jul 2005 19:59:39 -0700

I plan to integrate some C++ code with ObjC; ObjC being the driver/ main controller. There may be some exchanges between NSString & C++ Strings (C++ <string> library).

I'm aware that a C-string is a null-terminated array of characters; and that a C++ string is an object without the null and can be variable length.

So I guess my question is, can I use the same NSString method to convert a C-string and a C++ string, namely:

+ (id)stringWithUTF8String:(const char *)bytes?

... Or must I convert C++ string to a C-string to be converted to a NSString (rather wasteful, I would think)?

Regards,
Ric.






On Jul 1, 2005, at 5:13 PM, Cameron Hayne wrote:

You need to speak more precisely when talking about strings. There are a few different things that people refer to as strings - even within the context of one language.
In C, strings are arrays of characters terminated by null.
In C++ and ObjC, the same "C strings" exist as well, but there are also string objects - instances of a string class. In C++, the class is usually "string" and in ObjC, the class is usually NSString.


On Jul 1, 2005, at 5:19 PM, Ondra Cada wrote:


Frederick,

On 2.7.2005, at 1:12, Frederick C. Lee wrote:


I read that C strings are null terminated whereas C++ strings are not.
Which leads me to ask, is there any difference between C++ and ObjC strings?



ObjC as used in today's Cocoa (which is what is important here, right?) does not use C strings (aka arrays of chars) at all (but for compatibility with legacy code and other APIs). Instead, objects are used (NSString instances). They are *completely* different from C/C++ strings.
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc






_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: What's the difference between a C++ and ObjC String?
      • From: Steve Checkoway <email@hidden>
References: 
 >What's the difference between a C++ and ObjC String? (From: "Frederick C. Lee" <email@hidden>)
 >Re: What's the difference between a C++ and ObjC String? (From: Ondra Cada <email@hidden>)

  • Prev by Date: XML in NSTableView using Cocoa Bindings
  • Next by Date: Re: What's the difference between a C++ and ObjC String?
  • Previous by thread: Re: What's the difference between a C++ and ObjC String?
  • Next by thread: Re: What's the difference between a C++ and ObjC String?
  • Index(es):
    • Date
    • Thread