所以我们知道标准不强制指针大小相等。 ( here 和 here )(不讨论函数指针)
我想知道这在现实中怎么会成为一个问题。我们知道 void *
可以容纳任何东西,所以如果指针大小不同,那将是最大的大小。鉴于此,将 void **
分配给 char **
意味着麻烦。
我的问题是假设 void *
和 char *
具有相同的大小会有多危险?是否真的有一种架构不是这样的?
还有,16位dos也不是我想听的! ;)
最佳答案
void *
和 char *
保证具有相同的大小。
void **
不保证与 char **
具有相同的大小(但很可能在您的实现中它们会)。
(C99, 6.2.5p27) "A pointer to void shall have the same representation and alignment requirements as a pointer to a character type [...] Pointers to other types need not have the same representation or alignment requirements."
关于c - 从 void ** 转换为 char ** 有多危险,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11275713/