由于C指针会返回“ void *”,并且除了其自身的地址外,它还可能以某种方式引用malloc(size)保留的内存大小,因此我问自己“ void *”的声明是否实际上与类型“ void”用于执行过程,如果“ void *”实际上是一种自身包含诸如已分配内存块大小之类的信息的类型,则其“内部”结构类似于以下所示。
//An imaginary internal implementation of "type" void* used to create pointers
struct void*
{
char[4] address; //for 32bit systems;
int size; //memory block size;
};
void* ptr=malloc(10); //create a pointer called ptr of 10 bytes
Run Code Online (Sandbox Code Playgroud) 在一些讨论中,它声称void *是“指向void对象的指针”,但是在C标准6.5.3.4中,第2点被写为:“ sizeof运算符产生大小(以字节为单位)。操作数的类型。” 因此可以说函数sizeof()接收类型作为参数。
因此,编译器将void *视为类型?或*的使用仅用于语义解释?