在Objective-C中使用GCC __unused属性 [英] Using the GCC __unused attribute with Objective-C

查看:137
本文介绍了在Objective-C中使用GCC __unused属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Objective-C对象方法参数上使用__unused属性宏?我试着将它放置在参数声明的各个位置,但它会导致编译错误或似乎被忽略(即编译器在编译-Wall -Wextra时仍会生成未使用的参数警告)。



任何人都可以使用它吗?它只是不支持Objective-C吗?作为参考,我目前正在使用Apple的GCC 4.0.1版本。

解决方案

好的,我找到了答案...它似乎是执行Apple的gcc 4.0的一个错误。使用gcc 4.2,它按预期工作,正确的位置如下:

   - (void)someMethod:(id)__unused someParam ; 

如果任何人感兴趣,它在Objective-C发行说明中有记录: http://developer.apple.com/releasenotes/ Cocoa / RN-ObjectiveC / index.html#// apple_ref / doc / uid / TP40004309-DontLinkElementID_6

请注意, ,但正如我在我的问题中所述,它实际上不会做任何事情或压制编译器发出的未使用警告。



编辑:我向苹果提交了一个bug报告这 rdar:// 6366051


Is it possible to use the __unused attribute macro on Objective-C object method parameters? I've tried placing it in various positions around the parameter declaration but it either causes a compilation error or seems to be ignored (i.e., the compiler still generates unused parameter warnings when compiling with -Wall -Wextra).

Has anyone been able to do use this? Is it just unsupported with Objective-C? For reference, I'm currently using Apple's build of GCC 4.0.1.

解决方案

Okay, I found the answer... it appears to be a bug with the implementation of Apple's gcc 4.0. Using gcc 4.2 it works as expected and the proper placement is the following:

-(void)someMethod:(id) __unused someParam;

It's documented in the Objective-C release notes if anyone is interested: http://developer.apple.com/releasenotes/Cocoa/RN-ObjectiveC/index.html#//apple_ref/doc/uid/TP40004309-DontLinkElementID_6

As a note, your answer will compile, Louis, but as I stated in my question it won't actually do anything or suppress the unused warning issued by the compiler.

EDIT: I filed a bug report with apple for this rdar://6366051.

这篇关于在Objective-C中使用GCC __unused属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆