One blog related to Block of Objective-C says: when ARC enabled, the following codes:
typedef int (^blk_t)(int);
blk_t func(int rate)
{
return ^(int count){return rate * count;};
}
can be translated into C++ codes as below with the -rewrite-objc of clang:
blk_t func(int rate)
{
blk_t tmp = &__func_block_impl_0(__func_block_func_0, &__func_block_desc_0_DATA, rate);
tmp = objc_retainBlock(tmp);
return objc_autoreleaseReturnValue(tmp);
}
I tried do the translation with the following ways, but not succeed.
Question: How can I translate the ARC enabled Objective-C codes to cpp with the option -rewrite-objc of clang?
At last, I found the missing clang option: -fobjc-runtime; the rewrite works after specify the objc-runtime version. For example the following command:
clang -x objective-c -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.1.sdk -rewrite-objc -fobjc-arc -fblocks -mmacosx-version-min=10.11 -fobjc-runtime=macosx-10.11 -O0 test.m
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.