The correction is correct ;-)
Anyway, a question raises:
1) two pointer types are allowed to be of different sizes
Yes, that is correct.
2) the void pointer is guaranteed to store any other pointer's value
without loss of information
Well, that is almost correct. There is a guarantee with pointer to
void with respect to pointer to any object type. There is no
correspondence, defined conversion, or any other guarantee between
pointers to objects and pointers to functions.
Here is what the standard says:
"A pointer to void may be converted to or from a pointer to any
incomplete or object type. A pointer to any incomplete or object type
may be converted to a pointer to void and back again; the result shall
compare equal to the original pointer."
this leads to:
3) the size of a void pointer is guaranteed to be at least as big as the
size of any other pointers
If you read the quotation from the standard above, you will note that
it requires that pointer to void be able to hold all the useful
information from any other pointer to object type. A perverse
implementation could have pointers to void and character types
actually occupy less space than pointers to other object types,
although those larger pointers to other types could not use more bits.
if 3) is a correct deduction, then I don't see the point to impose that
an argument of printf used in conjunction with %p must be a void pointer.
There is nothing that requires that a compiler pass pointer to void
and, for example, pointer to int, in the same manner to functions.
printf() is a variadic function, where there is no prototype to tell
the compiler to convert the parameters, if necessary.
What happens if a particular compiler passes pointer to void in
register R3 and pointer to int in register R5?
Mainly, it is undefined behavior because the C standard says that it
is.
if 3) is incorrect, how do we assure that a conversion to void * cannot
lead to a loss of information?
Again, 3) is not necessarily correct. A compiler for a platform with
a 32-bit address space could have 32 bit pointers to void, and 64 bit
pointers to int, although it could only use 32 bits of the pointer to
int.
Thanks for clarifying this point.
--
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