site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com 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/Conc... "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). Eric Thanks for any insight! David _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/eric.gouriou%40pobox.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... 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. This email sent to eric.gouriou@pobox.com This email sent to site_archiver@lists.apple.com