N
Netocrat
S.Tobias said:[snip]Netocrat said:Not true.
Okay. :-| Then there must be something else wrong with you:
I wonder what it could be? I understand your arguments, and I don't
require you to agree with mine, but if you give them more
consideration, you will possibly find that they're at least reasonable.
Why do you keep writing things like this?
Because the void type is unique. It is the only type that is both
empty, incomplete and can never be completed. In that sense how can we
consider a void pointer as pointing to "an object"? - it is clear that
void is the only type that can never represent an object, so a void
pointer can never point to an object. It may, however, be validly
converted to a pointer type that does.
Void pointer *can*
point to *any* object, that's its main purpose.
Informally I would also use a statement like that. But I don't think
it's strictly true (and the standard's wording convinces me that it's
not).
We rely on 6.3.2.3#1 to be able to convert without information loss
from a non-void pointer to a void pointer and back again, but they are
different pointer types, and nothing in the standard says that when the
information is stored in a void pointer, that we must consider the
conceptual thing that is the "void pointer" to be "pointing to an
object"; the definition of the void type actually makes that wrong in
the strict sense (I agree that informally we might use such wording).
It's that
the object's value cannot be accessed through void type,
No value at all (==void,empty) can be accessed through the void type,
let alone an object.
the pointer has to be converted to other type (a different
pointer), but the whole expression is still based on the original
void pointer that points to that object, eg:
*(int*)vp;
If a void pointer doesn't point to an object, then where does
it point to?
How would you instead answer "what does it point to?"
I don't see a strictly correct answer to your question (informally I
would say that it points to the original object as you have been
claiming). I'd describe a void pointer rather as holding pointing
information in a form that can be transferred back to an object pointer
without loss of meaning. But I wouldn't describe it as an object
pointer itself.
Now regarding whether dereferencing a void pointer is defined
behaviour, I said:
I find the standard a little ambiguous here.
The first two sentences of 6.5.3.2#4 don't apply since by 6.2.5, void
is not an object, it's an incomplete type.
Can you see where that statement is coming from now? 6.5.3.2#4 says
that "if [the operand] points to an object, the result is an lvalue
designating the object", but since a void pointer by definition does
not point to an object, this statement doesn't apply to a void pointer.
That leaves things somewhat
undefined; the third sentence defines the resulting type, but is that
enough definition?
So all that's defined is that the result has void type. OK, given that
there is no such thing as a void object anyway, I'll answer my
question: yes, that's enough definition. So I'm satisfied that at
least this part of the standard defines and allows for the
dereferencing of a void pointer.
Now said:[*] Well, actually 6.5.3.2#4 says it is an lvalue, but I think
the Standard is again wrong; I think it deserves a DR, but first
I'll check that this isn't already known.
You have misinterpreted 6.5.3.2#4. The result is only an lvalue if the
operand points to an object, which strictly speaking a void pointer
doesn't.
The paragraph says: "if it points to an object, the result is an lvalue
designating the object". Your argument implies that the object type
that the lvalue locates can be different to the type of expression
representing it (in this case, void), which is plainly untrue.
Don't get me wrong - I know that it's sometimes legal to access objects
through an lvalue of type other than the object's originally designated
type (in particular I'm a thinking of a character type), but in those
cases conceptually the lvalue _is_ accessing an object of the same type
as itself (eg. a char can be considered as a special object within a
bigger object of different type), whereas in the case of void it is not
(void is not an object like char is; it is empty and incompletable, so
an lvalue represented by a void expression cannot validly locate any
"object" within a different object).