Re: void pointer cast segfaults
- From: Andreas Schmidt <schmidt.2004@xxxxxx>
- Date: Thu, 05 May 2005 00:07:38 -0400
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?
.
- Follow-Ups:
- Re: void pointer cast segfaults
- From: Christian Bau
- Re: void pointer cast segfaults
- From: Andreas Schmidt
- Re: void pointer cast segfaults
- References:
- void pointer cast segfaults
- From: Andreas Schmidt
- Re: void pointer cast segfaults
- From: Peter Nilsson
- void pointer cast segfaults
- Prev by Date: Re: hey abt the one and only printf!!
- Next by Date: Re: [OT] Re: Difference between C89 and C99?
- Previous by thread: Re: void pointer cast segfaults
- Next by thread: Re: void pointer cast segfaults
- Index(es):
Relevant Pages
|