Lawrence Kirby <lk****@netactive.co.uk> writes:
On Sat, 11 Jun 2005 23:44:45 +0000, pete wrote:
Lawrence Kirby wrote:
Note that in the description above there is no
such thing in C as a "byte
object" (objects always have a type),
a char object is a byte *sized* object.
An allocated object doesn't always have a type.
An allocated object is a grey area. The definition of the term "object"
says it is a region of data storage then contents of which can represent
values. Well a value in an object is an interpretation of a bit pattern
according to the rules of a type - if you have no type you can't represent
values.
Any object that is designated has a type, which is the type of the
expression used to designate it; section 6.3.2.1 p1.
Any object that is accessed has an effective type, which if it isn't
anything else is the type of the lvalue used to access it; section
6.5 p6.
Some objects have an "inherent type" in the sense that the memory
corresponds to (an instance of) a declared variable, and the variable
has a type. This "inherent type" shows up tacitly in the language of
6.5 p6, eg, "the declared type of the object, if any" (despite
effective type being defined only when accessing objects, and despite
the small inconsistency that variables, not objects, have a type
declared for them). Section 6.5 p6 specifically anticipates the
circumstance that an object not have an "inherent type", eg, "If a
value is stored into an object having no declared type ...".
Section 6.5 p7 imposes requirements on the relationship between the
type of an object (that was designated) and the effective type of an
object (that was accessed). Apparently there are no requirements
imposed on the relationship between type and effective type (or
"inherent type" for that matter), except in the case of access.
The language in the standard is confused about what the word "object"
means. It's defined (3.14) as 'a region of data storage in the
execution environment', but in lots of places in the text of the
standard it's used to mean something more like "an instance of a
variable". There is the example language above, talking about the
'declared type of the object', despite there being no definition of
what the "declared type" of an object is (at least not that I could
find). Also, although I don't have a reference, I'm pretty sure
I remember seeing a phrase like "an instance of the object", which
I took to mean that it's being used basically as a synonym for
variable.
To respond to the comment above - whenever an object is designated it
has a type, which is the type of the expression used to designate the
object; it is this type that is used to interpret what value might
be represented.
A region of storage need not have any type. Whenver that region of
storage takes part in a computation, a type is imposed on it by the
expression used to access it.