Re: what is typecasting a pointer to the type (void *)p mean?



On Wed, 25 Jan 2006 23:07:54 +0100, Michael Rasmussen <mir@xxxxxxxxx>
wrote:

>On Wed, 25 Jan 2006 22:56:57 +0100, Emmanuel Delahaye wrote:
>
>>
>> Somehow, yes. Note that the conversion from/to void* doesn't need an
>> explicit typecast.
>>
>Well, not always but in this situation it is mandatory:
>void foo(void *t) {
> printf("%s", (char *) t);
>}
>
>int main() {
> char *t = "test";
> foo(t);
> return 0;
>}
>
>So might as well use explicit casting since it is a lot more readable for
>an outsider which later has to maintain the code. IMHO

void foo(void *t) {
char *rt = t;
printf("%s", rt);
}

--
Al Balmer
Sun City, AZ
.



Relevant Pages