开发者

compiler error in a c program:indirection on type void*

void main()
{
void *v;
int integer=2;
int *i=&integer;
v=i;
printf("开发者_开发问答%d",(int*)*v);
}

this simple program will result in a compiler error saying:

Compiler Error. We cannot apply indirection on type void*

what exact does this error mean?


The error means exactly what it says. The error is triggered by the *v subexpression used in your code.

Unary operator * in C is often called indirection operator or dereference operator. In this case the compiler is telling you that it is illegal to apply unary * to a pointer of type void *.


You cannot dereference pointers to void (i.e., void *). They point to a memory location holding unknown data so the compiler doesn't know how to access/modify that memory.


Change:

printf("%d",(int*)*v);

to this:

printf("%d",*(int*)v);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜