在 LLVM GCC 4.2 中使用块时的编译问题
我不久前写了一个要点:https://gist.github.com/611157。它编译并运行正常。
我最近又回来看它,它不再符合要求。
我注意到它使用 LLVM 2.0 进行编译,没有任何问题或警告(然后运行并工作!)
使用 LLVM GCC 4.2 则无法编译。 我收到以下错误
error: incompatible block pointer types initializing 'signed char (^)(struct objc_object *, struct NSString *)', expected 'BOOL (^)(struct objc_object *, struct objc_object *)'
我感觉我的声明丢失或错误,但我不知道,所以我想我会问。
有人有什么想法吗?
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 with 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是你的块有 type:
但初始化和方法声明中的参数类型中的第二个参数都是 NSString*
将块定义更改为
我已经在 GCC 4.2、GCC 4.2 LLVM 和 Clang LLVM 1.6 中测试了上述内容。
使用
id
第二个参数,在前两种情况下,我在初始化行和将其作为参数传递给toDictionaryBlockingRelationships:
的行上都出现了错误Clang 案例我完全没有错误。使用
NSString*
作为第二个参数,三个编译都没有错误。The problem is that your block has type:
but the second parameter in both the initialisation and the parameter type in the method declaration is NSString*
Change your block definition to
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 totoDictionaryBlockingRelationships:
In the Clang case I got no error at all.With
NSString*
as the second parameter, there were no errors in all three compilations.