Keith Thompson said:
Tim Rentsch said:
Keith Thompson said:
While technically correct that "void *" doesn't point to an object of
type "void" because there's no such thing, I think it is convenient to
think of it in those terms.
I disagree. That is, I agree that it's technically correct (the
best kind of correct!), but I think it's correct in every other
sense as well. [snip elaboration]
I would say exactly the opposite - a pointer of type 'void *'
points at something of type void. In fact all valid addresses
(arguably even those pointing past the end of arrays) refer
to legimate void objects. Just because you can't /do/ anything
with those void objects, as such, doesn't make them any less
legimate.
So you believe that there's such a thing as a "void object"?
Sure. void is an object type -- an incomplete object type, but
still an object type. What's wrong with having there be void
objects?
An "object" is by definition a "region of data storage in the
execution environment, the contents of which can represent values".
For a void object, what is the size of this region, and what values
can its contents represent?
Same answers as for 'struct foo' when that is an incoomplete
type, namely, we don't know and we don't know. One thing
we _do_ know that is very useful is where the object starts.
Or for pointers to other incomplete types, or for null pointers.
Pointers to incomplete object types still refer to objects.
The null pointer case is a red herring, just like a pointer
to one-past-an-array - the pointer still provides a reference
to something of the referenced type, even if in some cases
we can't actually get a "thing" by dereferencing. We can't
get a "thing" by dereferencing a pointer to an incomplete
object type either, but there still can be an object there
of that type even if we don't know what it is.
I suggest that this is an oversight. I'll also note that it uses
the word "entity", not "object". Neither void pointers nor function
pointers refer to objects.
The word "entity" is used only because functions and objects
are different. A pointer-to-function refers to a function;
a pointer to an object type refers to an object, whether
it is of complete object type or incomplete object type.
The world is just a lot simpler if we assume that there are void
objects along with all the other kinds of objects. I'm sure a
consistent model can be constructed where a pointer-to-void
points to "nothing", but why would we do that when it will just
complicate things? For example, converting a pointer to a
pointer-to-character type gives a pointer to the first byte of
the object. If a (void*) pointer points to "nothing", converting
it to a (char*) will end up being undefined behavior. Those
kinds of problems seem like a big headache for no tangible value.