爲什麼 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章