On Nov 12, 6:39 pm, Juha Nieminen <nos...@thanks. invalidwrote:
Ron Natalie wrote:
It's also not the case that all pointers
need to be the same size.
Is that really so? I thought that it must be possible to cast any
pointer to and from a void*. If there were different-sized pointers then
it could be rather problematic.
It is, and your assumption is wrong. You can cast any pointer
to an object to void*, but all you are guaranteed then is that
you can cast it back to the original type without loss of
information. There are also guarantees concerning accessing
objects as arrays of char or unsigned char. All of which,
together, more or less imply that sizeof(void*) == sizeof(char*)
(an explicit requirement in the C standard), and that
sizeof(void*) >= sizeof(T*) for all object types T. I've worked
on systems where char* was larger than int*, and of course,
systems where void (*)() had a different size than char* were
quite frequent once upon a time---you can still find their
descendants in use today. (The same systems often had a size_t
which was smaller than a data pointer. And in some cases, data
pointers or function pointers which were larger than any
integral type.)
You cannot, of course, convert a pointer to function, or any
ponter to member, to a void*; an attempt to do so is an error,
and requires a diagnositic.
Some standards place stricter requirements on the
implementation: Posix does require object pointers and function
pointers have the same size and representation, for example.
--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34