• 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: Weak linked non-functions crashing on check under 10.5
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Weak linked non-functions crashing on check under 10.5


  • Subject: Re: Weak linked non-functions crashing on check under 10.5
  • From: Alastair Houghton <email@hidden>
  • Date: Thu, 10 Jan 2008 18:39:12 +0000

On 10 Jan 2008, at 16:19, Rosyna wrote:

I'm trying to weak link to some symbols to ensure backwards compatibility going into the future (say, with MDItem.h, for example).

But when I try to weak link something that is *not* a function, the application crashes on 10.5 if the symbol doesn't exist, even when I test for the symbol.

Below is a short example showing this. Do I do something wrong?

Yes. Remember that weak-linking works at the symbol level, and that the value of a function from code is equal to the address of its symbol. For a variable, however, the value of the variable from code is *not* the address of the symbol, but the contents of the memory at that address. The linker, however, just sees another symbol, so if it is weak linked and not present, it sets that symbol's value to zero.


So, unlike the function case, the correct test for a weak-linked variable is e.g.

  if (&kCTStyleNameKey != NULL)

rather than

  if (kCTStyleNameKey != NULL)

Kind regards,

Alastair.

--
http://alastairs-place.net



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Weak linked non-functions crashing on check under 10.5 (From: Rosyna <email@hidden>)

  • Prev by Date: Xcode 3 File and Project Templates?
  • Next by Date: Re: Xcode 3 File and Project Templates?
  • Previous by thread: Weak linked non-functions crashing on check under 10.5
  • Next by thread: Xcode 3 File and Project Templates?
  • Index(es):
    • Date
    • Thread