Alf P. Steinbach wrote:
* Kai-Uwe Bux:
>Alf P. Steinbach wrote:
>>* Stefan Ram:
"Alf P. Steinbach" <al***@start.nowrites:
>»An object is a region of storage that has a type.«
Not in C++.
»An object is a region of storage. [...] An object has a type«
ISO/IEC 14882:2003(E), 1.8
Sorry, a region of storage does not have a type.
The proposed definition of "object" does not entail the claim that any
region of storage has a type. It says that an object is a region of
storage that has a type.
You're contradicting yourself.
>If a region of storage does not have a type, it would not
qualify as an object according to the proposed definition.
I think that's true.
So it's not compatible with C++.
That sentence only talks about those regions of storage that are not object.
But if x is an object and objects are regions of storage, then some region
of storage _is_ the object x. In that case, that region of storage has a
type since the object x has a type.
>The standard, on the other hand, is very clear that some regions of
storage have types (namely those regions of storage that happen to be
objects).
Chapter & verse please.
You have already been given the necessary quotes:
[1.8/1]: An object is a region of storage. ["object" in italics]
Note that this is a conceptual stipulation that identifies objects with
regions of storage. Consequently, all attributes of an object become
attributes of the region of storage that this object happens to be (there
is no conceptual distinction between the object and the region of storage
that it _is_).
Therefore, when the standard goes [in the same clause] to say that objects
have storage duration, lifetime, and type it _follows_ that certain regions
of storage (namely those that happen to be objects) have storage duration,
lifetime, and type.
Should be corrected if anything so bad has managed to sneak into the
standard! :-)
Maybe. The standard could say "An object occupies a region of storage" or
"An object has a region of storage". But the standard chose to use "is" and
thereby chose to identify objects and their regions of storage on a
conceptual level. Whether that decision is _wise_ is a different matter.
BTW: This is very much like the differences of materialist and
non-materialist accounts of what a human is. Materialist would say a human
_is_ a body and non-materialists would say a human _has_ a body. The former
would then go on to say that if humans had immortal souls, it would follow
that certain bodies had immortal souls. (This is one of the reasons that
materialists tend to be critical of religion and that religious
philosophers tend to be critical of materialism. Both agree that the
inference is valid:-)
>>A region of storage may be part of many objects, with different types.
Yes, and nothing in the proposed definition of "object" would contradict
that.
It does.
How so? Let's say you have an object x of type T which has a member x.a of
type S. Also, suppose that x_ptr is a char* so that
[x_ptr, x_ptr+sizeof(T) )
_is_ the object X and a_ptr is a char* so that
[a_ptr, a_ptr + sizeof(S) )
_is_ the object x.a. Then the region [a_ptr, a_ptr+sizeof(S) ) has type S
and the region [x_ptr, x_ptr + sizeof(T) ) has the type T. Of course, that
even goes when the two regions of storage coincide. BTW: in that case, x
and x.a _are_ the same(!) object according to the standard (which makes
more sense that one might think at first: after all any change to x will
affect a).
Although there exists a silly convoluted interpretation (reading
"has" as "is associated with" and "a" as "at least one") where it doesn't.
There is nothing silly about it. It just follows straight from the
identification made by the standard.
However, it doesn't matter, for it goes only to the practical reason why
regions of storage are not regarded as having types.
Understanding the difference between storage (untyped) and object (typed)
is
fundamental. For example, a void* doesn't point to storage of type void.
But it's no big deal to take that untyped storage and make an object out
of it via e.g. placement new.
I think it's wrong of you to try to sow confusion about this distinction.
You may not like the conceptual identification of objects with regions of
storage, but the italics in the standard [1.8/1] make it very clear that
the statement "An object is a region of storage" is meant as a definition
of the term object. Since it is supposed to be a definition, it makes an
identification on the conceptual level (for better or worse).
Maybe, what one would want is something like "an object is a typed region of
storage". So, two objects would be the same if and only if they occupy the
same region in memory _and_ have the same type. Creation of an object could
then be regarded as the act of typing a certain region of memory.
BTW: I don't think the identification is actually all that harmful. The
standard is not a book to teach C++ but just a specification that should
allow one to deduce the observable behavior of C++ programs. I do not (yet)
see how that [1.8/1] or my interpretation of it negatively impacts on that.
Best
Kai-Uwe Bux