比如void *P=...;
那么*P表示什么?
warning: dereferencing 'void *' pointer [enabled by default]
error: invalid use of void expression
void*类型定义的指针变量只接收对象的地址,没有对象的类型概念。所以该指针变量是不能直接用
“*指针变量”去访问对象的,只能经强制类型转换后才能“间接”访问:*(type*)指针变量,必须
给出正确的type!
比如:
void *accept_request(void *pclient)
{
int client = *(int *)pclient; //这才是正确的写法
。。。
}
如果按照下面的写法,就会报上面的错误
void *accept_request(void *pclient)
{
int client = *pclient; //错误的写法
。。。
}
那么*P表示什么?
warning: dereferencing 'void *' pointer [enabled by default]
error: invalid use of void expression
void*类型定义的指针变量只接收对象的地址,没有对象的类型概念。所以该指针变量是不能直接用
“*指针变量”去访问对象的,只能经强制类型转换后才能“间接”访问:*(type*)指针变量,必须
给出正确的type!
比如:
void *accept_request(void *pclient)
{
int client = *(int *)pclient; //这才是正确的写法
。。。
}
如果按照下面的写法,就会报上面的错误
void *accept_request(void *pclient)
{
int client = *pclient; //错误的写法
。。。
}