Tim Rentsch said:
James Kuyper said:
Tim said:
[snip]
char *endp;
printf("endp is %p\n", endp);
printf("endp is %p\n", (void*)endp);
The first [printf line] is almost certainly safe; it would take a
deliberately perverse implementation to break it. [snip]
To say this more practically: there has never been, nor
will there ever be, an ISO-conforming C implementation in
which there is the slightest difference in run-time behavior
between these two cases.
Keep in mind that "practically" means that the any a absolute terms
such as "never" or "ever" should be understood in a non-absolute
sense. In reality, as opposed to "practicality", it's entirely
possible that such an implementation may some day be created, even if
only for the purpose of proving that it can be done.
It's entirely possible that the Earth will spontaneously
tunnel 93 million miles into the center of the Sun, but that
doesn't mean it's ever worth worrying about.
It's far more likely that an implementation would treat char* and
void* pointers differently in some way; for example an optimizing
compiler might assume that a char* value won't be passed where a void*
value is expected, and perform some optimization based on that
assumption. (No, I can't think of a plausible optimization that this
would enable.)
The standard says that "The same representation and alignment
requirements are meant to imply interchangeability as arguments to
functions, return values from functions, and members of unions.", but
it says so only in a footnote. If we're going to take the standard
seriously, we must take seriously the statement in paragraph 6 of the
foreward:
Annexes D and F form a normative part of this standard; annexes
A, B, C, E, G, H, I, J, the bibliography, and the index are
for information only. In accordance with Part 3 of the ISO/IEC
Directives, this foreword, the introduction, notes, footnotes,
and examples are also for information only.
If the authors had meant to require char* and void* to be fully
interchangeable, they could easily have said so in normative text.