My best-effort reading of the C specification (C99, primarily) makes me think that it is valid to cast (or implicitly convert, where void *
's implicit conversion behavior applies), between any of these types:
void *
, char *
, signed char *
, unsigned char *
I expect that this will trigger no undefined behavior, and that those pointers are guaranteed to have the same underlying representation.
Consequently, it should be possible to take a pointer of either one of those four types that is already pointing to an address which can be legally dereferenced, typecast and/or assign it to one of the three char type pointers, and dereference it to access the same memory, with the only difference being whether your code will treat the data at that location as a char
, signed char
, or unsigned char
.
Is this correct? Is there any version of the C standard (lack of void *
type in pre-standardization C not withstanding) where this is not true?
P.S. I believe that this question is answered piecemeal in passing in a lot of other questions, but I've never seen a single clear answer where this is explicitly stated/confirmed.