Let’s say you start with a void pointer, or a char pointer, or an int pointer, or whatever you would like to name.
void *p = // initialized to something here
And we do a conversion like
*((int *)((char *)p + 6)) = 5;
Does this mean we are basically casting a void pointer to a char pointer, doing some arithmetic, casting that to an int pointer, and then de-referencing it to store 5?
Or do we need to cast the char pointer back to a void pointer before it is safe to cast it to the int pointer?
* Also, before casting from char* to int*, does there need to be a de-reference somewhere before the conversion?
The conversion you have shown is syntactically valid C. Casting through a
void *type on the way toint *makes no difference.Whether it is semantically correct depends on whether the memory pointed to by
(char *)p + 6is correctly sized and aligned for access asint.