char a[] = "123";
char b[] = "abc";
Cast 'a' and 'b' to void *.
Correct me if I'm wrong, but isn't this technically a case where it
shouldn't matter, seeing as char * and void * have the exact same
representation?
Yes and no. It doesn't matter, they are compatible in this case, but
not because they have the same representation.
Pointer to void and pointer to any of the three character types are
required to have the same size and representation, but nowhere does
the C standard that they be passed to functions in the same manner, in
the absence of a prototype.
The relevant definition on representation is 6.2.5 p26, first
sentence:
"A pointer to void shall have the same representation and alignment
requirements as a pointer to a character type.39)"
Where the "39)" is a reference to footnote 39, on the same page:
"39) The same representation and alignment requirements are meant to
imply interchangeability as arguments to functions, return values from
functions, and members of unions."
My reading of this is that implementations are strongly urged, but not
required, to make them compatible in all of these situations. It is a
quality of implementation whether they are or not.
But in the particular case of an argument to *printf() to match a "%p"
conversion specifier, compatibility is guaranteed by specific wording
in the standard by 6.5.2.2 p6.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html