• 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: Weakly-Linked Symbols
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Weakly-Linked Symbols


  • Subject: Re: Weakly-Linked Symbols
  • From: Eric Gouriou <email@hidden>
  • Date: Tue, 28 Oct 2008 22:43:54 -0700


On Oct 28, 2008, at 9:39 PM, Dave Keck wrote:

Hey everyone,

This is the most appropriate list I could find for this question
pertaining to building weakly-linked libraries and frameworks.

Here's a quote from
http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html

"Note: When checking for the existence of a symbol, you must
explicitly compare it to NULL or nil in your code. You cannot use the
negation operator ( ! ) to negate the address of the symbol."

I was simply wondering why this is - what's different between this:

   if ( !mySymbol )

and this:

   if ( mySymbol == NULL )

to check whether the symbol exists or not? My understanding of C seems
to suggest that comparing something with NULL would be precisely the
same thing as comparing it with 0 (overlooking the (void *) cast).

I can only guess that this advice was meant to avoid a compiler optimisation that
would defeat the check "if (!mySymbol)" but not "if (mySymbol == NULL)".


Unfortunately current gcc releases end up assuming that no symbol can be NULL
either and also optimize away the "if (mySymbol == NULL)" check. This makes
weak-linking pretty hard to use these days.


If you are in control of the weak-linked framework, the current advice is to use
__attribute__((weak_import)) on its exported functions. Naively I'd recommend
only doing so in cases where the library is indeed weak-linked and avoiding
the attribute being present in normal cases, however I don't know for sure
that it will make the code any worse if always present. Caveat programmor.


  Eric

Thanks for any insight!

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

_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Weakly-Linked Symbols (From: "Dave Keck" <email@hidden>)

  • Prev by Date: Weakly-Linked Symbols
  • Next by Date: "Purity" patches for IOKitUser, launchd, objc4
  • Previous by thread: Weakly-Linked Symbols
  • Next by thread: "Purity" patches for IOKitUser, launchd, objc4
  • Index(es):
    • Date
    • Thread