In the book, Modern C by Jens Gustedt, following statements have been made by the author,
- In the following subsections, we will introduce the syntactical aspects (grammar) and three different semantic aspects: declarative parts (what things are), definitions of objects (where things are), and statements (what things are supposed to do).
Conceptually, it is important to distinguish the box itself (the object), the specification (its type), the box contents (its value), and the name or label that is written on the box (the identifier). In such diagrams, we put ?? if we don’t know the actual value of an item.
- Generally, declarations only specify the kind of object an identifier refers to, not what the concrete value of an identifier is, nor where the object it refers to can be found. This important role is filled by a definition .
--QUESTIONS REGARDING THE AFOREMENTIONED STATEMENTS--
Q.1. - The first and third statements from the author imply that Definitions specify where the object referred to by the identifier can be found. What does 'where' mean here, in particular how is specifying a concrete value of an identifier in definition same/different from where the object the identifier refers to is?
Q.2. - From statement 2, what does 'Conceptually, it is important to distinguish the box itself (the object), the specification (its type), the box contents (its value), and the name or label that is written on the box (the identifier).' mean? Why's the 'box' an object here and not the value in the 'box'?
CodePudding user response:
An object is a place where values can be stored. That's the terminology used by the language.
Formally, an object is a
region of data storage in the execution environment, the contents of which can represent values
Q.2: The four bytes of allocated memory with value 123 inside it is called an object in a broader sense. You have a house with 4 rooms & an address. But not to forget you can also name your house like 'dexter's home'. So here 'a'
is the name/label you can use to refer to a particular location of memory when writing C code for your ease.
Note all these four boxes of bytes are considered a single box by the author, double
actually takes eight bytes(on 64 bit) but the author has drawn a single box for simplicity.