Avatar of naseeam
naseeam
Flag 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?

C

Avatar of undefined
Last Comment
evilrix

8/22/2022 - Mon
evilrix

Yes.
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
evilrix

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck