What is “the issue” with variable qualifier placement?

你。 提交于 2019-12-04 08:53:49

See my examples with gibberish to English translations

It is well known that

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

has different meaning than

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

or

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

In the same way this declaration

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

and this declaration

__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.

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!