I cut this question out of my last question because i thought this was rather an individual question. So i found the passages for pointer conversion in the standard from which the ones regarding my question are:
6.3.2.3
Pointers
1 A pointer to void may be converted to or from a pointer to any object type. A pointer toany object type may be converted to a pointer to void and back again; the result shall compare equal to the original pointer.
...
4 Conversion of a null pointer to another pointer type yields a null pointer of that type. Any two null pointers shall compare equal.
Now it only states that
(originaltype*)((void*)ptr) == ptr
shall always be true but what about
(void*) ptr == ptr
It is not explicitely stated wether this shall be true or false. Or do i misinterpred the 1 paragraph?
C 2018 6.5.9 discusses
==. Paragraph 2 specifies constraints, and(void *) ptr == ptrsatisfies the constraints because one of the options is “one operand is a pointer to an object type and the other is a pointer to a qualified or unqualified version ofvoid”. Then paragraph 5 says “… If one operand is a pointer to an object type and the other is a pointer to a qualified or unqualified version of void, the former is converted to the type of the latter.”Thus, in
(void *) ptr == ptr, the right operand is converted to(void *), so the expression is equivalent to(void *) ptr == (void *) ptr, and we may expect it evaluates to true.Strictly speaking, the clause on pointer conversion, 6.3.2.3, tells us only that the result of converting
(void *) ptrback to its original type will compare equal toptr. It does not tell us anything else about the value of(void *) ptr, and so, considering only this clause, it is possible that two different instances of(void *) ptrwill produce different results, as long as they contain sufficient information to produce something that will compare equal to the originalptrwhen converted back.Back at 6.5.9, paragraph 6 tells us:
Now, certainly we expect
(void *) ptr == (void *) ptrto be true at least some of the time. How is this possible?(void *) ptris not a null pointer (assumingptrwas not), nor do we expect this case is covered by the end of one array and start of another case. So we expect that, when(void *) ptr == (void *) ptrevaluates to true, it must be because it is in the “pointers to the same object” case or the “pointers to one past the last element of the same array object case”. That seems like the only reasonable way to interpret the standard. If so, then this case (whichever one is the one that applies sometimes) must apply all the time, and the “if and only if” tells us that(void *) ptr == (void *) ptris always true.