It is a familiar feature of C that a void*
can be assigned to or from any pointer variable. In N1570, the draft standard document for C11, this is specified in 6.3.2.3 Pointers
:
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.
But 6.2.7 Compatible type and composite type
says
All declarations that refer to the same object or function shall have compatible type; otherwise, the behavior is undefined.
Yet, as far as I can see, that section does not say void*
is compatible with other pointer types. So:
int x = 5;
int *xp = &x;
void *vp = xp;
is expected to be perfectly valid by tradition and 6.3.2.3
, but would seem to be undefined behavior by 6.2.7
.
What am I missing?