J
Jack Klein
Richard Heathfield said:The representations of char * and void * are so closely related [...]
In fact, they are so closely related that they are required to be
the same:
A pointer to void shall have the same representation and
alignment requirements as a pointer to a character type.
(C99 6.2.5#26)
Yes, of course, and this has been true since ANSI89/ISO90.
But there is neither requirement nor guarantee in the standard that
pointer to void and pointer to char are passed to functions in the
same way, whether the functions are variadic or not.
gcc is taking advantage of its knowledge that it passes pointer to
void and pointer to char in the same way, and therefore the result
will be identical.
I doubt that there are many, or even any, implementations that pass
the two pointer types differently but nothing in the standard forbids
it, and such an implementation would be conforming.
So the behavior is undefined, as the standard says about all
mismatches between *printf() conversion specifiers and arguments.
As we often maintain here, even the fact that every single compiler in
existence, past present and future, performs exactly the same for a
specific instance of undefined behavior does not make the behavior
defined.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq