• 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: Framework Weak Linking Weirdness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Framework Weak Linking Weirdness


  • Subject: Re: Framework Weak Linking Weirdness
  • From: David Aames <email@hidden>
  • Date: Sat, 7 Jul 2007 12:50:55 +0100

Hi,

Why do you think I'm comparing the return value of the function? The function is never called (I have no () after the function name) so I'm always comparing the address of the function.

Thanks,
David

On 7 Jul 2007, at 12:40, Dominik Pich wrote:

Well in the first case you compare the return value of the function (a BOOL) while in the second case you compare the function pointer to nil.
I dont think C specifies 'ret = BOOL from Null Pointer Function'
....
so comparing ret doesnt do it.


Regards,
Dominik

Am 07.07.2007 um 13:18 schrieb David Aames:

Hi all,

I've been experimenting with weak linking a simple framework. To strip out all the unnecessary parts, my framework only contains one C function. The function signature is BOOL isFrameworkAvailable (void); The purpose of this function is for the user of the framework to determine whether the framework is available because if it is the linker will assign it a valid address.

Now here comes the tricky part. Because I'm weakly linking the whole framework I pass "-weak_framework MyFrameworkName" as Other Linker Flags. This works as expected. If I run the application and the framework is in place and I do a comparison like if (isFrameworkAvailable == NULL) - it evaluates to false. Here's the problem. If I delete the framework and re-run the app it still doesn't equal NULL (here's the catch). But if I do something like:

void* ptr = isFrameworkAvailable;
if(ptr == NULL)

Now this comparison returns true as supposed. The question is why do I have to go through that intermediate stage? Is this a bug or I'm not doing things properly? I should note that if I print out isFrameworkAvailable using NSLog it prints the value as 0x0 but compared to 0x0 doesn't return true (I find this weird).

The solution which I found is to apply __attribute__ ((weak_import)) to the function signature. But I thought that if I link to the whole framework weakly (-weak_framework) then the compiler adds this declaration to all symbols.

On a side note, there is no way to apply the weak link attribute to a ObjC class because really when it's compiled it's a call to objC_msgSend. So all classes are kind of weakly linked by default, am I right? Or not?

Many thanks,
David
_______________________________________________

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



_______________________________________________

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: Framework Weak Linking Weirdness
      • From: Dominik Pich <email@hidden>
References: 
 >Framework Weak Linking Weirdness (From: David Aames <email@hidden>)
 >Re: Framework Weak Linking Weirdness (From: Dominik Pich <email@hidden>)

  • Prev by Date: Re: Framework Weak Linking Weirdness
  • Next by Date: Re: Framework Weak Linking Weirdness
  • Previous by thread: Re: Framework Weak Linking Weirdness
  • Next by thread: Re: Framework Weak Linking Weirdness
  • Index(es):
    • Date
    • Thread