是“NSString * __unused aString”和“NSString__unused * aString”当量? [英] Are "NSString * __unused aString" and "NSString __unused * aString" equivalent?
问题描述
-
是
NSString * __unused aString
和NSString __unused * aString
-
- (void)aMethod:(NSString * __unused)aString
-
如果答案是是,我应该选择哪种形式是正确的?
<当启用/停用 GCC_WARN_UNUSED_PARAMETER
和 GCC_WARN_UNUSED_VARIABLE
指令时,这两种格式的两种格式似乎都一样。
我没有找到任何信息来澄清这一点。
相关主题: / p>
__ unused Flag行为/用法(具有目标C的GCC)
两者之间有区别。
当属性 __未使用
出现在星号之前时,它会装饰整个声明列表的主类型。所有变量将未使用:
__unused NSString * foo,* bar; // 好。所有变量在语句中未使用。
NSString __unused * foo,* bar; // OK
但是放在 *
后面将仅适用于第一个变量:
NSString * __unused foo,* bar; //未使用的变量'bar'
我更喜欢 NSString * __unused foo;
因为它看起来更清楚我不会隐藏罕见的情况下,当我在一个语句中声明多个变量。
GCC属性语法参考在第6.31节中提到它:
一个属性说明符列表可能会出现在声明器
(不是第一个)之前,用逗号分隔的声明器列表中的
声明多个标识符使用单个列表
说明符和限定符。这种属性说明符仅适用于出现其声明符之前的
标识符。例如,在__attribute __((noreturn))void d0(void),
__attribute __ ,1,2)))d1(const char *,...),
d2(void)
noreturn属性应用于所有声明的函数; format属性只适用于d1。
Are
NSString * __unused aString
andNSString __unused * aString
equivalent, when they are variable declarations?Are
- (void)aMethod:(NSString * __unused)aString
and- (void)aMethod:(NSString __unused *)aString
equivalent, when they are Objective-C method parameter declarations?If the answer is "yes", what form should I prefer as correct?
Both forms in both cases seem to work identically when enabling/disabling GCC_WARN_UNUSED_PARAMETER
and GCC_WARN_UNUSED_VARIABLE
directives.
I didn't find any information to clarify this.
Relevant topics:
__unused Flag Behavior/Usage (GCC with Objective C)
There is a difference between the two.
When the attribute, __unused
, appears before the star, it decorates the primary type of the entire declaration list. All variables will be "unused":
__unused NSString *foo, *bar; // OK. All variables are unused in the statement.
NSString __unused *foo, *bar; // OK
But when placed after the *
, it will only apply to the first variable:
NSString * __unused foo, *bar; // Unused variable 'bar'
I prefer NSString * __unused foo;
because it seems more clear to me and won't hide the rare case when I declare multiple variables in one statement.
The GCC Attribute Syntax reference mentions it in Section 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.
这篇关于是“NSString * __unused aString”和“NSString__unused * aString”当量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!