• 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
Is @"constantstring" pointer equal to @"constantstring" a guarantee?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is @"constantstring" pointer equal to @"constantstring" a guarantee?


  • Subject: Is @"constantstring" pointer equal to @"constantstring" a guarantee?
  • From: Nathan Vander Wilt <email@hidden>
  • Date: Thu, 27 Mar 2008 18:20:43 -0500 (CDT)

If I make two identical string constants
(@"samestring" and @"samestring") in my Cocoa program,
are their pointers guaranteed to be equal? I assumed
this without thinking while prototyping root objects
in an NSOutline view and it did work, however I just
realized that perhaps I shouldn't rely on this
behaviour.

The compiler documentation
(http://developer.apple.com/documentation/developertools/gcc-4.0.1/gcc/Constant-string-objects.html)
doesn't say either way. The CFString documentation
(http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFStrings/Articles/CreatingAndCopying.html)
says about the CFSTR() macro: "If there are two or
more exact instances of a constant string in an
executable, in some cases only one might be stored."
Which I'll take to mean that in some cases two or more
might be stored.

However, when I get to the documentation for the
@"..." construct
(http://developer.apple.com/documentation/Cocoa/Conceptual/Strings/Articles/CreatingStrings.html)
it says "The compiler makes such object constants
unique on a per-module basis...".

So does that mean once I'm up at the Cocoa level, that
constant strings *are* guaranteed to have the same
pointer if their contents are the same? What is
"unique" and what is a "module" in this context?

thanks,
-natevw



      ____________________________________________________________________________________
¡Capacidad ilimitada de almacenamiento en tu correo!
No te preocupes más por el espacio de tu cuenta con Correo Yahoo!:
http://correo.espanol.yahoo.com/
_______________________________________________

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: Is @"constantstring" pointer equal to @"constantstring" a guarantee?
      • From: Jens Alfke <email@hidden>
    • Re: Is @"constantstring" pointer equal to @"constantstring" a guarantee?
      • From: Bill Bumgarner <email@hidden>
  • Prev by Date: Re: NSMapTable with pointer keys ?
  • Next by Date: Re: NSScroller question
  • Previous by thread: Re: Static in Subclasses
  • Next by thread: Re: Is @"constantstring" pointer equal to @"constantstring" a guarantee?
  • Index(es):
    • Date
    • Thread