- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
当 NSString * __unused aString
和 NSString __unused * aString
是变量声明时,它们是否等价?
- (void)aMethod:(NSString * __unused)aString
和 - (void)aMethod:(NSString __unused *)aString
等价,当它们是 Objective-C 方法参数声明吗?
如果答案是"is",我应该选择哪种形式才是正确的?
在启用/禁用 GCC_WARN_UNUSED_PARAMETER
和 GCC_WARN_UNUSED_VARIABLE
指令时,两种情况下的两种形式似乎工作相同。
我没有找到任何信息来阐明这一点。
相关主题:
最佳答案
两者是有区别的。
当属性 __unused
出现在星号之前时,它装饰整个声明列表的主要类型。所有变量都将是“未使用的”:
__unused NSString *foo, *bar;//好的。语句中未使用所有变量。
NSString __unused *foo, *bar;//好的
但是放在*
之后,它只会作用于第一个变量:
NSString * __unused foo, *bar;//未使用的变量 'bar'
我更喜欢 NSString * __unused foo;
因为它对我来说更清晰并且不会隐藏我在一个语句中声明多个变量时的罕见情况。
GCC Attribute Syntax引用资料在第 6.31 节中提到了它:
An attribute specifier list may appear immediately before a declarator (other than the first) in a comma-separated list of declarators in a declaration of more than one identifier using a single list of specifiers and qualifiers. Such attribute specifiers apply only to the identifier before whose declarator they appear. For example, in
__attribute__((noreturn)) void d0 (void),
__attribute__((format(printf, 1, 2))) d1 (const char *, ...),
d2 (void)the noreturn attribute applies to all the functions declared; the format attribute only applies to d1.
关于objective-c - "NSString * __unused aString"和 "NSString __unused * aString"等价吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21153156/
当 NSString * __unused aString 和 NSString __unused * aString 是变量声明时,它们是否等价? - (void)aMethod:(NSString
我曾经看到过宏 __unused 的用法,对此进行了解释 here ,但由于某种原因我现在找不到它的定义位置。将不胜感激的帮助。我需要它用于 ansi C 项目。谢谢。 最佳答案 unused 是 G
使用 -Wunused-parameter 标志,您可以对未使用的参数强制执行 __unused,作为编译器优化。以下代码会导致两个警告: #include int main(int argc, c
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求提供代码的问题必须表现出对所解决问题的最低限度理解。包括尝试过的解决方案、为什么它们不起作用,以及预
是否可以在 Objective-C 对象方法参数上使用 __unused 属性宏?我试过将它放在参数声明周围的不同位置,但它要么导致编译错误,要么似乎被忽略(即,编译器在使用 -Wall -Wextr
我刚刚了解了使用 GCC 编译时可以使用的 __unused 标志,我了解的越多,我的问题就越多... 为什么编译时没有警告/错误?我特地告诉编译器我不会使用变量,这似乎很奇怪,然后当我使用它时,一切
我是一名优秀的程序员,十分优秀!