什么是“问题"?可变的预选赛位置? [英] What is "the issue" with variable qualifier placement?

查看:92
本文介绍了什么是“问题"?可变的预选赛位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此文档中在标有变量限定符"的部分下,苹果说:

In this document, under the section labeled "Variable Qualifiers", Apple says:

您应该正确修饰变量.在对象变量声明中使用限定符时,正确的格式为:

You should decorate variables correctly. When using qualifiers in an object variable declaration, the correct format is:

ClassName * qualifier variableName;

例如:

MyClass * __weak myWeakReference;
MyClass * __unsafe_unretained myUnsafeReference;

其他变体在技术上不正确,但被编译器原谅".要了解此问题,请参见 http://cdecl.org/.

看cdecl.org并不能澄清任何事情.谁能解释他们所指的问题"?换句话说,请帮助我说服其他人,这实际上很重要,而不仅仅是因为这个自述文件这么说."

Looking at cdecl.org doesn't clarify anything. Can anyone explain what "the issue" they are referring to is? In other words, help me convince others that this actually matters in a way that isn't just "because this one readme says so."

推荐答案

查看我的带有乱码的英语翻译示例

See my examples with gibberish to English translations

众所周知,

ClassName * const varName; //varName is a constant pointer to ClassName

const ClassName * varName; //varName is a pointer to constant ClassName

ClassName const * varName; //varName is a pointer to constant ClassName

以同样的方式声明

ClassName * __weak varName; //varName is a weak pointer to ClassName

此声明

__weak ClassName * varName; //varName is a pointer to weak?? ClassName??

非常不同.但是,第二个含义很明确(尽管从技术上讲是不正确的),编译器可以原谅".

are VERY different. However, the meaning of the second one is clear (although it's technically incorrect) and it can be "forgiven" by the compiler.

一旦您开始使用指向指针的指针(例如Foo * __autoreleasing *),正确性就变得更为重要.

The correctness is a bit more important once you start working with pointers to pointers (e.g. Foo * __autoreleasing *).

我认为他们想保护初学者免受C/C ++声明的干扰.一开始就有预选赛似乎很自然.

I assume they wanted to protect beginner developers from the C/C++ declaration gibberish. Having the qualifier in the beginning seems more natural.

这篇关于什么是“问题"?可变的预选赛位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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