Link to home
Start Free TrialLog in
Avatar of naseeam
naseeamFlag for United States of America

asked on

Can void pointer be casted to char and then re-casted to void?

void * ptr;
Can ptr be casted to pointer to char.  Then, can it be re-casted to pointer to void?

Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Yes.
Avatar of naseeam

ASKER

I don't think ptr needs to be re-casted to void because eventhough we casted it to char, it's still a void pointer, isn't it?

Example:

void somefunc(void * some_ptr);

void * ptr;
char * some_ptr;

some_ptr = ((char *)ptr)++;

/* I shouldn't need to recast ptr to void before passing it as an argument to a function */
somefunc(ptr);     /* will this work? */

ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial