In the context of another question there was some discussion on whether it was allowed (i.e. would or would not introduce implementation defined or undefined behavior) to cast int**
to void**
and subsequently assign a value to the dereferenced void*
. This brings me to my question on the interpretation of the C11 standard
6.2.5 (28) A pointer to void shall have the same representation and alignment requirements as a pointer to a character type. ...
6.3.2.3 (1) A pointer to void may be converted to or from a pointer to any object type. A pointer to any object type may be converted to a pointer to void and back again; the result shall compare equal to the original pointer.
6.3.2.3 (7) ... When a pointer to an object is converted to a pointer to a character type, the result points to the lowest addressed byte of the object. ...
My question is whether this
int* intptr = NULL;
void* dvoidptr = &intptr; /* 6.3.2.3 (1) */
*(void**)dvoidptr = malloc(sizeof *intptr); /* using 6.3.2.3 (1) */
conforms with the standard or not? It seems strange to me, but I cannot find a conclusive line of argument why not. void*
to void**
is guaranteed by 6.3.2.3 and 6.2.5 together with 6.3.2.3 help with the alignment.