Re: void pointer cast segfaults



Peter Nilsson wrote:

> Andreas Schmidt wrote:
>> I am trying to understand the behavior of void pointers.

> The conversion of an int to a void * is implementation defined.
>
>> }
>> int main(){
>> void* w1 = (void*)10;
>
> Again the conversion is implementation defined. It is utterly useless
> in portable programming because you have _no idea_ what 10 will
> represent when converted to a pointer.

I don't think it's utterly useless. The following program works fine:

#include <stdio.h>
int main(){
void* i = (void*)10;
printf("%d\n", (int*)i);
return 0;
}

What do you mean by "implementation specific"? Are you saying I'm just
lucky that it compiles and runs, but it depends on the implementation of
the compiler?




.



Relevant Pages