[问题] 物件的定义 .. 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