为什么 C 中的箭头 (->) 运算符存在? - Why does the arrow (->) operator in C exist?

问题:

The dot ( . ) operator is used to access a member of a struct, while the arrow operator ( -> ) in C is used to access a member of a struct which is referenced by the pointer in question.点 ( . ) 运算符用于访问结构的成员,而 C 中的箭头运算符 ( -> ) 用于访问由相关指针引用的结构的成员。

The pointer itself does not have any members which could be accessed with the dot operator (it's actually only a number describing a location in virtual memory so it doesn't have any members).指针本身没有任何可以用点运算符访问的成员(它实际上只是一个描述虚拟内存中位置的数字,因此它没有任何成员)。 So, there would be no ambiguity if we just defined the dot operator to automatically dereference the pointer if it is used on a pointer (an information which is known to the compiler at compile time afaik).因此,如果我们只是定义点运算符以在指针上使用指针时自动取消引用指针(编译器在编译时已知的信息 afaik),则不会有歧义。

So why have the language creators decided to make things more complicated by adding this seemingly unnecessary operator?那么为什么语言创建者决定通过添加这个看似不必要的操作符来让事情变得更加复杂呢? What is the big design decision?什么是重大设计决策?


解决方案:

参考一: https://en.stackoom.com/question/u57z
参考二: https://stackoom.com/question/u57z
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章