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



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

--
Hilsen/Regards
Michael Rasmussen
http://keyserver.veridis.com:11371/pks/lookup?op=get&search=0xE3E80917

.



Relevant Pages

  • Re: what is typecasting a pointer to the type (void *)p mean?
    ... >> explicit typecast. ... not always but in this situation it is mandatory: ... >void foo{ ... >int main{ ...
    (comp.lang.c)
  • Re: Concept of Statements and Expressions
    ... its expression has a function type. ... Later down this post, where you use the phrase "a class conversion", ... conversion to result in a void expression? ... to the issue of expression statement evaluation. ...
    (comp.lang.c)
  • Re: gcc knows about malloc()
    ... If a correct prototype is visible, this expression (after the implicit ... actual conversion and simply yields the same pointer-to-function ... this value to type void *. ...
    (comp.lang.c)
  • Re: srand(time(NULL))
    ... conversion of void * to whatever_type * is implicit). ... you should cast it to void*. ...
    (comp.lang.c)
  • Re: cast to void *
    ... When else is implicit conversion to 'void *' done, ... Except that conversion between void* and struct tm is a constraint ...
    (comp.lang.c)