First of all, let me say that I am sorry to ask couple of different things on a single SO question but they are all related and I don't know how to separate them.
In the book, From Mathematics to Generic Programming
, Alexander Stepanov makes following definitions.
Defnition 10.1. A datum is a sequence of bits.
01000001 is an example of a datum.
Defnition 10.2. A value is a datum together with its interpretation.
So 65 and character 'A' are two different values that can share the same datum if we are to implement them as such in memory.
Defnition 10.3. A value type is a set of values sharing a common interpretation.
Up until this point, things are not really about programming. These definitions are more of a philosophical nature. For example, Leibniz could have created a taxonomy of all knowledge using something similar.
Things get related to computers here.
Defnition 10.4. An object is a collection of bits in memory that contain a value of a given value type.
Defnition 10.5. An object type is a uniform method of storing and retrieving values of a given value type from a particular object when given its address.
So an object is a way to represent things in memory and object type is a way to work with these representation in a programming language. Compiler tracks the relation between object and corresponding object type so I can express abstractions in my program. In light of these definitions, here are couple of questions.
Take a look at following code.
int b = 5;
int& a = b;
std::cout << a + b;
I can get that int
is an object type. But;
What is
a
,b
? Are they variables, identifiers, objects? From the definitions, they don't seem like objects. Do they have object types? If so, they should be an object. Do objects have values?What is the type of
a
, if these things indeed have types? To this day I thought its type isreference to an int
but are references also object types? If so,int
andint &
seems like completely same object types.For an rvalue, we know it has a related object in memory so they have related value types, value and data as well. But do rvalues have object types as well? I am asking these because they are region of storage in the sense of being an object wrt. C++ standard but they are not addressable so it seems like they fail to be objects in the Stepanovian sense.
You see, I have a lot of confusion to be cleared up.