K
Kai-Uwe Bux
Irrwahn said:Kai-Uwe Bux said:Julie wrote:
[Discussion about what constitutes a variable]
may I offer a tentative definition for the term "variable" that hopefully
describes the way I use the term: To me a variable is a textual
representation of an lvalue within a piece of source code. The lvalue
condition distinguishes variables from arbitrary expressions. A variable
can change its value, and the basic means of accomplishing that is the
assignment. For instance, I consider "*p" a variable whenever "p" deontes
a pointer to something non-const.
It is clear from the definition I gave that there can be literally
thousands of variables that refer to the same memory location.
What is your prefered definition of variable?
For c.l.c++: I think the definition from the standard should apply:
"A variable is introduced by the declaration of an object.
The variable's name denotes the object."
This definition has a funny consequence: the variable *is* the object. The
reason is that if some expression is the "name of X", then this expression
"denotes X". Since the "name of the variable" is supposed to "denote the
object", the object better be the variable. Below, you seem to adopt this
point of view.
For c.lc: there's no definition of the term variable.
Personally, I'm not happy with both versions. I'd rather go with
something like:
"A variable is a modifiable object which is designated
by its declared name."
Somewhere else, I proposed:
"A variable is an identifier denoting an lvalue."
The difference is that I consider the variable to be the identifier not the
object it designates.However, the standard seems to side with you.
However, with neither definition *p is a variable, though it's an
expression that evaluates to an lvalue designating an actual object,
provided the variable p (sic!) holds a valid pointer value.
Correct.
What about non-const reference parameters? Are those variables? I have the
strong inclination to think of parameters as local variables initialized by
the caller.
Best
Kai-Uwe Bux