[問題] 物件的定義 .. function為何不是物件?

作者: alpho (Whyyyyy)   2018-04-05 12:33:32
編譯器 : VC 13
問題(Question):
我在找關於"物件的定義"時候,有看到2014草案
內容是說
An object is a region of storage.
[ Note: A function is not an object, regardless of whether or not it occupies storage in the way that objects do.
—end note ]
這樣。
google之後,得到了這一篇:
https://stackoverflow.com/questions/43971298/why-is-a-function-not-an-object
不過我實際嘗試之後,用int函式指標紀錄一個函式,然後用()轉成void、再轉回(int*)()
值是不變的?
當然回到本來的問題,連結內文提到:
C++ requires that you can convert a pointer to any object type into a pointer
to void,..
略,就是指標轉過去在轉回來的值應該要是一樣的,這部份也是定義嗎?
原文下面證明函式不是物件就是用這個敘述去講,希望以下我沒理解錯
原文:
That's not true with a pointer to a function though
作者: LPH66 (-6.2598534e+18f)   2018-04-05 12:43:00
對 C/C++ 來說, 函式指標和物件指標是兩種東西而 void * 是一個物件指標, 拿它去指函式指標可能會有問題至於之所以為什麼要分開, 你貼的那篇 SO 文的回答後半有提是存在這種架構其中函式指標跟物件指標是完全不同的兩回事(連指標大小都可能不一樣) 因此互轉的過程中就會掉東西極端狀況例如哈佛架構裡程式和資料是物理上分開的它們的指標可以很不一樣, 因此也就沒有互轉這回事

Links booklink

Contact Us: admin [ a t ] ucptt.com