gpt4 book ai didi

c: void 的大小*

转载 作者:太空狗 更新时间:2023-10-29 16:25:12 28 4
gpt4 key购买 nike

我对 C 中的 void* 指针有点困惑。尤其是在阅读了这个问题之后:Is the sizeof(some pointer) always equal to four? ,有人说不能保证 sizeof(int *) == sizeof(double *)

我的问题是:是否可以保证 sizeof(void*) >= sizeof(any other pointer type)?换句话说,我是否可以始终将 some_type* 指针分配给 void* 指针,然后将其取回为 some_type*?

最佳答案

只有数据指针。 void * 可以容纳任何数据指针,但不能容纳函数指针。

这是一个C FAQ .

void *'s are only guaranteed to hold object (i.e. data) pointers; it is not portable to convert a function pointer to type void *. (On some machines, function addresses can be very large, bigger than any data pointers.)

至于第一部分,是的,不同类型可以有pointers of different sizes :

关于c: void 的大小*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6908686/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com