Re: Weak linked non-functions crashing on check under 10.5
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