Compilation issue when using blocks with LLVM GCC 4.2
I wrote a gist a while ago: https://gist.github.com/611157. It compiled and worked ok.
I came back to it recently and it no longer complied.
I noticed it compiles 开发者_如何学JAVAwith LLVM 2.0 with no problems or warnings (and then runs and works!)
With LLVM GCC 4.2 it fails to compile. I get the following error
error: incompatible block pointer types initializing 'signed char (^)(struct objc_object *, struct NSString *)', expected 'BOOL (^)(struct objc_object *, struct objc_object *)'
I have the feeling I have a declaration missing or wrong, but I don't know, so I thought I would ask.
Any ideas anyone?
The problem is that your block has type:
BOOL (^blockRelationship)(id,id)
but the second parameter in both the initialisation and the parameter type in the method declaration is NSString*
Change your block definition to
BOOL (^blockRelationship)(id,NSString*)=^(id obj,NSString* relationship) { ... } ;
I've tested the above in GCC 4.2, GCC 4.2 LLVM and Clang LLVM 1.6.
With the id
second parameter, in the first two cases I got your error appearing on both the initialisation line and the line where it is passed as a parameter to toDictionaryBlockingRelationships:
In the Clang case I got no error at all.
With NSString*
as the second parameter, there were no errors in all three compilations.
精彩评论