weak-linking

GCC -O2 and __attribute__((weak))

故事扮演 提交于 2021-01-02 08:29:37
问题 It looks like GCC with -O2 and __attribute__((weak)) produces different results depending on how you reference your weak symbols. Consider this: $ cat weak.c #include <stdio.h> extern const int weaksym1; const int weaksym1 __attribute__(( weak )) = 0; extern const int weaksym2; const int weaksym2 __attribute__(( weak )) = 0; extern int weaksym3; int weaksym3 __attribute__(( weak )) = 0; void testweak(void) { if ( weaksym1 == 0 ) { printf( "0\n" ); } else { printf( "1\n" ); } printf( "%d\n",

GCC -O2 and __attribute__((weak))

痞子三分冷 提交于 2021-01-02 08:28:17
问题 It looks like GCC with -O2 and __attribute__((weak)) produces different results depending on how you reference your weak symbols. Consider this: $ cat weak.c #include <stdio.h> extern const int weaksym1; const int weaksym1 __attribute__(( weak )) = 0; extern const int weaksym2; const int weaksym2 __attribute__(( weak )) = 0; extern int weaksym3; int weaksym3 __attribute__(( weak )) = 0; void testweak(void) { if ( weaksym1 == 0 ) { printf( "0\n" ); } else { printf( "1\n" ); } printf( "%d\n",

GCC -O2 and __attribute__((weak))

[亡魂溺海] 提交于 2021-01-02 08:27:37
问题 It looks like GCC with -O2 and __attribute__((weak)) produces different results depending on how you reference your weak symbols. Consider this: $ cat weak.c #include <stdio.h> extern const int weaksym1; const int weaksym1 __attribute__(( weak )) = 0; extern const int weaksym2; const int weaksym2 __attribute__(( weak )) = 0; extern int weaksym3; int weaksym3 __attribute__(( weak )) = 0; void testweak(void) { if ( weaksym1 == 0 ) { printf( "0\n" ); } else { printf( "1\n" ); } printf( "%d\n",

GCC -O2 and __attribute__((weak))

感情迁移 提交于 2021-01-02 08:27:10
问题 It looks like GCC with -O2 and __attribute__((weak)) produces different results depending on how you reference your weak symbols. Consider this: $ cat weak.c #include <stdio.h> extern const int weaksym1; const int weaksym1 __attribute__(( weak )) = 0; extern const int weaksym2; const int weaksym2 __attribute__(( weak )) = 0; extern int weaksym3; int weaksym3 __attribute__(( weak )) = 0; void testweak(void) { if ( weaksym1 == 0 ) { printf( "0\n" ); } else { printf( "1\n" ); } printf( "%d\n",

How to access weak linked framework in iOS?

。_饼干妹妹 提交于 2020-02-20 05:17:11
问题 I want to use Twitter framework for iOS 5, but be able to run my app in older OS. I added weak referenced framework (i.e. set "optional" flag) in Xcode 4.2 Target settings. Base SDK is iOS 5, iOS deployment Target is iOS 3.2. Next, I try to use Twitter framework: #import <Twitter/Twitter.h> ... Class twClass = NSClassFromString(@"TWTweetComposeViewController"); if (!twClass) // Framework not available, older iOS { [self shareWithTwitterPriorIOS5]; return; } if ([TWTweetComposeViewController

How to access weak linked framework in iOS?

早过忘川 提交于 2020-02-20 05:16:03
问题 I want to use Twitter framework for iOS 5, but be able to run my app in older OS. I added weak referenced framework (i.e. set "optional" flag) in Xcode 4.2 Target settings. Base SDK is iOS 5, iOS deployment Target is iOS 3.2. Next, I try to use Twitter framework: #import <Twitter/Twitter.h> ... Class twClass = NSClassFromString(@"TWTweetComposeViewController"); if (!twClass) // Framework not available, older iOS { [self shareWithTwitterPriorIOS5]; return; } if ([TWTweetComposeViewController

how can you find out if an NSObject has a certain property?

时光总嘲笑我的痴心妄想 提交于 2020-01-01 08:12:49
问题 Let's say in Apple API version 1.0, there is a class NSFoo with a property 'color'. API 1.1 adds property 'size'. I want to know whether I can use the getter: myFoo.size [myFoo respondsToSelector:@selector(getSize)] doesn't work as expected. What's the correct way to find out if an object has a property? Thanks! 回答1: You're close. Your selector should be exactly the message you want to send to the object: if ( [myFoo respondsToSelector:@selector(size)] ) { int size = [myFoo size]; // or myFoo

GCC style weak linking in Visual Studio?

心不动则不痛 提交于 2019-12-27 11:58:29
问题 GCC has the ability to make a symbol link weakly via __attribute__((weak)) . I want to use the a weak symbol in a static library that users can override in their application. A GCC style weak symbol would let me do that, but I don't know if it can be done with visual studio. Does Visual Studio offer a similar feature? 回答1: MSVC++ has __declspec(selectany) which covers part of the functionality of weak symbols: it allows you to define multiple identical symbols with external linkage, directing

Weak Linking - check if a class exists and use that class

帅比萌擦擦* 提交于 2019-12-27 11:02:07
问题 I'm trying to create a universal iPhone app, but it uses a class defined only in a newer version of the SDK. The framework exists on older systems, but a class defined in the framework doesn't. I know I want to use some kind of weak linking, but any documentation I can find talks about runtime checks for function existence - how do I check that a class exists? 回答1: TLDR Current: Swift : if #available(iOS 9, *) Obj-C, iOS : if (@available(iOS 11.0, *)) Obj-C, OS X : if (NSClassFromString(@

Weak Linking - check if a class exists and use that class

廉价感情. 提交于 2019-12-27 11:01:25
问题 I'm trying to create a universal iPhone app, but it uses a class defined only in a newer version of the SDK. The framework exists on older systems, but a class defined in the framework doesn't. I know I want to use some kind of weak linking, but any documentation I can find talks about runtime checks for function existence - how do I check that a class exists? 回答1: TLDR Current: Swift : if #available(iOS 9, *) Obj-C, iOS : if (@available(iOS 11.0, *)) Obj-C, OS X : if (NSClassFromString(@