5
votes

The standard states that

An entity is a value, object, reference, function, enumerator, type, class member, template, template specialization, namespace, parameter pack, or this.

This implies that a "variable" is not an entity.

But further in the standard said:

Every name that denotes an entity is introduced by a declaration. Every name that denotes a label is introduced either by a goto statement (6.6.4) or a labeled-statement (6.1).

and

A variable is introduced by the declaration of a reference other than a non-static data member or of an object. The variable’s name denotes the reference or object.

I'm assume from this two quotes that a variable is a name.

It is because the variable is introduced by declaration of reference and every name that denotes entity introduced by a declaration. But what does a variable's name mean? A variable is also a name by definition.

4

4 Answers

2
votes

I'm assume from this two quotes that a variable is a name.

No, from the quotes you provided, a variable is an object or a reference which has a name.

It is because the variable is introduced by declaration of reference and every name that denotes entity introduced by a declaration.

The declaration introduces both the variable (the object or reference), and its name. This doesn't imply that that variable is the name, just that both are introduced by the declaration.

2
votes

The definition of the term variable is a bit ambiguous in this respect, but by looking at the various uses of the term variable in the c++ standard, it looks like a variable is a special kind of entity. It is either an object or a reference. However, not all objects or references are variables, only the ones introduced the way described in [basic]/6:

A variable is introduced by the declaration of a reference other than a non-static data member or of an object. The variable's name, if any, denotes the reference or object.

Note that some variables are unnamed, for example the parameter of the function f in the example below:

void f(int) {}

int main() {}
0
votes

The best simple definition I can think of is: a Variable is trio of name, address and type (usually implies a size).

Originally it was meant to hold a changeable value but some languages allow this value to be constant (write once).

0
votes

A variable is, as you say, the name of "a something". That "a something" is either a reference (to another object) or an object. Note that object here does not infer "an instance of a class", so an object could be a char, array of int, or pointer to void.

This name is held by the compiler, and when code is generated, space somewhere is allocated for the variable [1], in a register or on the stack (local variables) or in "data space" (static or global variables). This gives the variable a location, an address (note that registers don't have addresses).

[1] Variables can also be eliminated if the compiler finds that the variable isn't used [or, sometimes replaced, when for example a loop optimisation is changed from one form of loop to another]