[Q]Object:formal definition and description?

Discussion in 'C++' started by Steven T. Hatton, Apr 4, 2004.

  1. This may seem like such a simple question, I should be embarrassed to ask
    it. The FAQ says an object is "A region of storage with associated
    semantics." OK, what exactly is meant by "associated semantics"? What, if
    any, associated semantics are shared by all objects? That part seems to go
    beyond the FAQ.

    Does anybody know of a resource that discusses (focuses on) this topic?
    Steven T. Hatton, Apr 4, 2004
    1. Advertisements

  2. No, I know of no resource, but the statement "a region of storage with
    associated semantics" is sorta kinda equivalent to "data with operations
    related to that data".

    Does that help?

    Mark A. Gibbs, Apr 5, 2004
    1. Advertisements

  3. Steven T. Hatton

    bartek Guest

    Associated semantics define behaviour (probably a bad word) in some

    For example, an object in the context of C++ *can be* for example "A
    region of storage with a set of methods defined". Of course this much
    more specific than what you've quoted.
    I don't mean to sound harsh, but this question reminds me of "Why the
    earth is spherical".
    A technical dictionary?
    comp.object newsgroup?

    bartek, Apr 5, 2004
  4. I'd accept something like how it is influenced by or influences the outcome
    of programmatic operations. Maybe. Now, could I take an example such as
    int, and provide an itemized list of related semantics? Not without a lot
    more thinking than I've already done. I suspect scope, name resolution,
    declaration, initialization, definition (yes I know), conversion, duration,
    possible operations, referencing, etc. Would all be part of the semantics
    of an object of type int. But to provide a comprehensive, orthogonal and
    clearly specifying list of semantics would be quite a challenge.
    I actually was faced with the interesting situation of meeting a reasonably
    intelligent person who did *not* understand the concept that the earth is
    spherical. He was from Eritrea, and had very little formal education. I
    explained it to him in terms of Newtonian gravitation (without explicit
    reference to the inverse-square force law.) But the Earth isn't exactly
    spherical, and that takes a bit of explaining, as well. Nonetheless, I can
    begin with simple concepts of classical physics and come up with a very
    good approximation to what the shape of the Earth should be, and find that
    it matches the observed reality. IOW, the question about the Earth is not
    quite as simple as it seems at first, but it is answerable on the basis of
    reasonably sound first principles.

    Part of what I'm trying to get at is how much of the definition of the
    concept of object is defined explicitly by the Standard, and how much is
    defined by consequence of definitions which associate semantics with
    specific categories of objects as 'side effects'? What /are/ the first
    Steven T. Hatton, Apr 5, 2004
  5. Think about this: in mathematics, which is thought of as fairly strict and
    well-defined, perhaps the most well-defined of all possible fields, nobody can
    agree on even what _kind_ of answers that question has. Yet mathematicians
    can collaborate and can (to good approximation) understand each other's good
    work, although not the bad. It's the same way in programming, only more so.
    Alf P. Steinbach, Apr 5, 2004
  6. Steven T. Hatton

    bartek Guest

    Because we see the world as somewhat "object oriented" ?

    Sorry, perhaps because I look at C++ from a rather practical standpoint,
    I can't imagine myself going into so much formal analysis and intricate
    details, which actually bring no significant conclusions. I tend to take
    it as it is.

    I admire your quest for knowledge, and I'm jealous for the amounts of
    spare time. :)
    bartek, Apr 5, 2004
  7. The Teachings of the Buddha from the Dhammapada, page 1, verse 1:

    1 All the phenomena of existence have mind as their precursor, mind as their
    supreme leader, and of mind are they made. If with an impure mind one
    speaks or acts, suffering follows him in the same way as the wheel follows
    the foot of the drawer (of the chariot).

    2. All the phenomena of existence have mind as their precursor, mind as
    their supreme leader, and of mind are they made. If with a pure mind one
    speaks or acts, happiness follows him like his shadow that never leaves
    I think I have a reasonably good answer. See the excerpt from the Standard
    quoted below.
    If you knew the whole story, you might not be quite so jealous.

    <title>[intro.object] 1.8</title>

    <subtitle>The C++ object model</subtitle>

    1 The constructs in a C + + program create, destroy, refer to, access,
    and manipulate objects. An object is a region of storage. [Note: A
    function is not an object, regardless of whether or not it occupies
    storage in the way that objects do. ] An object is created by a
    definition (3.1), by a new-expression (5.3.4) or by the implementation
    (12.2) when needed. The properties of an object are determined when
    the object is created. An object can have a name (clause 3). An object
    has a storage duration (3.7) which influences its lifetime (3.8). An
    object has a type (3.9). The term object type refers to the type with
    which the object is created. Some objects are polymorphic (10.3); the
    implementation generates information associated with each such object
    that makes it possible to determine that object s type during program
    execution. For other objects, the interpretation of the values found
    therein is determined by the type of the expressions (clause 5) used
    to access them.
    2 Objects can contain other objects, called sub-objects. A sub-object
    can be a member sub-object (9.2), a base class sub-object (clause 10),
    or an array element. An object that is not a sub-object of any other
    object is called a complete object.
    3 For every object x, there is
    some object called the complete object of x, determined as follows: If
    x is a complete object, then x is the complete object of x.
    Otherwise, the complete object of x is the complete object of the
    (unique) object that contains x.
    4 If a complete object, a data member
    (9.2), or an array element is of class type, its type is considered
    the most derived class, to distinguish it from the class type of any
    base class subobject; an object of a most derived class type is called
    a most derived object.
    5 Unless it is a bit-field (9.6), a most derived object shall have a
    non-zero size and shall occupy one or more bytes of storage. Base
    class sub-objects may have zero size. An object of POD4) type (3.9)
    shall occupy contiguous bytes of storage.
    6 [Note:C++ provides a variety of built-in types and several ways of
    composing new types from existing types (3.9). ]
    Steven T. Hatton, Apr 5, 2004
  8. Steven T. Hatton

    Jack Klein Guest

    Splurge, spend $18.00, buy a copy of the standard.

    The definition of an object in C++ is basically inherited from ISO C
    and has nothing at all to do with classes or OO terminology.

    An object is indeed a region of storage. Objects have specific
    properties. The two irreducible minimum properties, determined at the
    time of the object's creation, are storage duration and type.

    Given the trivial but complete program below:

    int x;
    int main(void)
    int y;
    return 0;

    x is an object of type int with static storage duration. y is an
    object of type int with automatic storage duration.

    x happens to have external linkage and y happens to have no linkage,
    but these are properties of the identifiers, not of the objects

    For more information, see 1.8 of ISO 14882:1998.
    Jack Klein, Apr 5, 2004
  9. The Standard isn't completely clear on some of the points I'm asking about.
    The standard certainly doesn't say /that/, and I'm not convinced your
    assertion is completely accurate. I'm aware of common OO terminology. I'm
    also aware there are differences between their meanings when used by
    different authors or to described different languages. It seems the term
    "object" in the C++ Standard identifies the set of all fundamental and
    aggregate type instances, and descriptions of the behavior of objects are
    intended, unless otherwise specified, to apply to all objects. So either
    we allow that the term object is being used in an OO sense, or we assert
    that the general use of the term 'object' in the C++ standard is not used
    to describe object oriented features of the language.
    Is that stated in the standard? If so, where? Does it apply to all
    objects, or only complete objects? What are the semantic implications of
    having a type?
    And this relates to my question in what way?
    Does ISO 14882:2003 suffice? I already posted 1.8 from the current C++
    Standard. Was there something missing? I don't have the older version you
    Steven T. Hatton, Apr 5, 2004
  10. Actually, objects are things that *could* occupy a region of storage.
    Good optimizing compilers can and do "optimize away" the storage
    for some objects that contain intermediate results for example.
    The "associated semantics" have to do with the object's type.
    An int and a float may be represented by the same number of bits
    but the type determines how those bits are interpreted
    and what operations may be applied to them.

    In the context of a computer programming language,
    an object is a *data* object. The type of an object can be
    a User Defined Type (UDT) as well as a built-in type.
    C++ programmers implement UDTs as class definitions.
    At best, a UDT is the implementation of an Abstract Data Type (ADT).

    In the context of Object Oriented Programming (OOP),
    the program does not generally know exactly which method
    (operation, function, etc.) applies to an object
    without first inspecting the object at runtime
    to determine the actual type of the object.
    This is called "run-time polymorphism" or "dynamic binding"
    and is, for some object oriented programmers, the essential feature
    of objects and object oriented programming.
    The comp.object newsgroup.
    E. Robert Tisdale, Apr 5, 2004
  11. Steven T. Hatton

    Jorge Rivera Guest

    int is not an object in C++.

    I think you should not worry about the syntax. You are not a lawyer.

    Write code, observe behavior, find references to and question things
    which you don't understand.

    Too many lawyers in newsgroups these days...


    Jorge Rivera, Apr 6, 2004
  12. It is a type.

    int j = 0;

    j is an object of type int with an initial value of zero.
    Too many programmers practicing language law without a license.
    E. Robert Tisdale, Apr 6, 2004
  13. Steven T. Hatton

    Ron Natalie Guest

    int is an object in C++. It's just not a class.
    Ron Natalie, Apr 6, 2004
  14. No!

    int is a *type* -- a built-in type.
    An object is an *instance* of some type:

    int j = 0;

    j is an *object* of type int.
    E. Robert Tisdale, Apr 6, 2004
  15. An int is a type of object in C++. Most people probably do not think of an
    instance of int as being an object. This is an issue that keeps coming
    back to me as I learn more about the language.
    I believe this is a question of semantics, not syntax.
    That's why I started asking. I'm reading the Standard, and its use of the
    term 'object' is not consistent with my preconceived notions. IIRC, a guy
    named Jerry Feldman once told me where in TC++PL(SE) Stroustrup explains
    certain characteristics of fundamental types as resulting from the fact
    they are actually objects, and therefore obey the rules applicable to all
    My reason for asking is actually more pragmatic than it may seem. I /do/
    enjoy the study of languages, both natural and designed. That really isn't
    my primary motive, however. I am trying to understand the language
    definition better.
    Steven T. Hatton, Apr 6, 2004
  16. I'm starting to wonder whether a pointer is an object in C++ parlance. I
    have found no statement clearly excluding pointers from the set of all C++
    objects. In the case of functions, they are explicitly excluded. The same
    question might be asked of a reference.
    Steven T. Hatton, Apr 6, 2004
  17. "Pure mathematics consists entirely of such asseverations as that, if such
    and such a proposition is true of anything, then such and such another
    proposition is true of that thing... It's essential not to discuss whether
    the proposition is really true, and not to mention what the anything is of
    which it is supposed to be true... If our hypothesis is about anything and
    not about some one or more particular things, then our deductions
    constitute mathematics. Thus mathematics may be defined as the subject in
    which we never know what we are talking about, nor whether what we are
    saying is true."- Bertrand Russell

    However, mathematics relies on definitions which are commonly accepted, and
    understood at least in so much as to lead other mathematicians to
    manipulate symbols in such a way as to produce results their peers will
    understand as equivalent to their own. IOW, mathematics can be viewed as
    an exercise in deterministic symbol manipulation.

    There is a field called metamathematics which studies the mechanisms of
    mathematics. I don't know if there is formally a field called axiomatics,
    but I certainly believe there has been much study along the lines suggested
    by the term. One view is that of Euclid which holds certain principles are
    fundamental and selfevident. Another view holds that axioms can be posited
    at will, and the only test of their validity is whether they can be shown
    not to be mutually derivable, and not to lead to inconsistencies. Which of
    course begs a few questions....

    But for the sake of programming, I tend to believe some concepts can, and
    should be clearly defined, at least for pragmatic purposes.
    Steven T. Hatton, Apr 6, 2004
  18. Pointers are objects. They take on a value, may have an address, and have
    associated operations.
    A function may have an address and has associated operations, but it cannot
    have a value.
    A reference isn't an object, but an alias for an object. A reference has no
    address (the address is that of the aliased object), no value (the value is
    that of the aliased object), and no associated operations other than its
    initial binding (all other operations are on the aliased object).

    Claudio Puviani
    Claudio Puviani, Apr 6, 2004
  19. That's kind of what I expected.
    I have an easier was to determine that a function isn't an object. It is
    explicitly stated in 1.8 of the Standard.
    I have yet to really examine references, but that was more or less what I
    expected. Does this mean references aren't really runtime 'things'? IOW,
    are they bound to something else at compile time? I believe what I'm
    asking is whether references are always static.

    I know my level of understanding of references is below that which I can
    gain from carefully reading the FAQ, so I'll do my homework before pursuing
    it further.

    This is a somewhat telling passage from 3.5:

    "A name is said to have linkage when it might denote the same object,
    *reference*, function, type, template, namespace or value as a name
    introduced by a declaration in another scope:..." (*emphasis* mine)

    So we can probably assume the namable 'things' in the list other than object
    are not objects. Note that this includes references.
    Steven T. Hatton, Apr 6, 2004
  20. Wrong question. The key point is that a C++ reference cannot be re-seated;
    if a reference R refers now to object X, then R refers to object X until R
    ceases to exist. There are no operations on the reference itself, and in
    many cases (but not all) it need not occupy any storage.
    Alf P. Steinbach, Apr 6, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.