Discussion:
What is a variable?
(too old to reply)
a***@gmail.com
2015-05-14 19:59:10 UTC
Permalink
Raw Message
The standard seems quite precise in its use of the noun 'variable'.
There is no entry for 'variable' either in the terms list in section 3
(not even as a deprecated term) or the index. Almost always in
normative text, 'variable' is used as an adjective, as in
'variable length array' or 'variable arguments'. 7.6 (fenv.h)
describes certain 'system variables'.

There are however quite a lot of uses of 'variable' (noun) in the
non-normative footnotes, where it seems to mean an object.

Then finally, 7.17 (atomics) uses 'variable' freely in normative
text, and 7.21 (threads) uses 'condition variable'.

So is 'variable' a synonym for 'object with an identifier' or just
'object'? Is an element of an aggregate, a variable? A bit field?
Or does it specifically mean an atomic object - is its use in 7.17
significant, rather than sloppy? Does it need defining in section 3?
Derek M. Jones
2015-05-15 00:32:29 UTC
Permalink
Raw Message
Al,
Post by a***@gmail.com
So is 'variable' a synonym for 'object with an identifier' or just
'object'? Is an element of an aggregate, a variable? A bit field?
Or does it specifically mean an atomic object - is its use in 7.17
significant, rather than sloppy? Does it need defining in section 3?
Normative references are intended to cover terms that are not defined
in the document.

"2. Normative references

The following referenced documents are indispensable for the application
of this document.
...
4 ISO/IEC 2382−1:1993, Information technology — Vocabulary — Part 1:
Fundamental terms."

Oops, no definition of "variable" here:
https://law.resource.org/pub/in/bis/S04/is.14692.1.1999.pdf

Where we need to look is part 15: of ISO 2382:

ISO/IEC 2382/l5 ‘Data processing -Vocabulary - Part 15 Programming
languages’

4.1 Variable - A language object that may take different values, one
at time.
https://law.resource.org/pub/in/bis/S04/is.1885.52.15.1986.pdf
Kaz Kylheku
2015-05-15 01:25:24 UTC
Permalink
Raw Message
Post by Derek M. Jones
ISO/IEC 2382/l5 ‘Data processing -Vocabulary - Part 15 Programming
languages’
4.1 Variable - A language object that may take different values, one
at time.
https://law.resource.org/pub/in/bis/S04/is.1885.52.15.1986.pdf
Ah, but a "language object" seems to be something declared. All occurrences
to "language object" seem to be connected to naming in some way.

In these excerpts LO is an abbreviation for "language object",
for emphasis:

2.1 Identifier - A lexical unit which names a LO.

3.1 Declaration - The mechanism for establishing a LO.

3.4 Built-in/Predefined - Pertaining to a LO that is
declared by the definition of the programming language.

Note 2 under 3.5 Scope - A LO may not be referable
throughout its scope since it may be hidden by the declaration of
the same identifier in an inner block.

3.6 Local - With respect to a block, qualifies a LO having
a scope contained in that block.

3.7 Global - With respect to a block, qualifies a LO having
a scope extending beyond ...

3.8 External - Qualifies a LO having a scope extending
beyond one module.

3.11 Lifetime - Of a LO, that portion of the execution time
during which the object exists.

3.12 Reference - A language construction, such as an identifier,
designating a declarad LO.

3.13 Qualification - A mechanism for referencing a component of a language
object b means of a reference to the object and an identifier declared
for the component.

4.1 Variable - [ already noted ]

4.2 Constant - A LO that takesonly one specific value.

4.9 Actual Parameter/Argument - A LO that appears in
a procedure call [...]

5.5 Indirect Referencing - A mechanism for referencing via a data object
whose value points to the referenced LO.

Note 2 under 5.5 - The referencing may be done along a chain of data objects in
which each data object, except the last, points to the next, the last data
object pointing to the referenced LO.
a***@gmail.com
2015-05-18 08:46:43 UTC
Permalink
Raw Message
Post by Derek M. Jones
4.1 Variable - A language object that may take different values, one
at time.
https://law.resource.org/pub/in/bis/S04/is.1885.52.15.1986.pdf
That still doesn't answer the question of exactly what can/can't
be a 'variable' (e.g. can a bit field be a variable?), or whether
its use in 7.17 and 7.21 is significant. Would 7.17 and 7.21 have
the same normative meaning if 'variable' was replaced by 'object'?
James Kuyper
2015-05-18 11:31:06 UTC
Permalink
Raw Message
Post by a***@gmail.com
Post by Derek M. Jones
4.1 Variable - A language object that may take different values, one
at time.
https://law.resource.org/pub/in/bis/S04/is.1885.52.15.1986.pdf
That still doesn't answer the question of exactly what can/can't
be a 'variable' (e.g. can a bit field be a variable?), ,,,
A bit-field is a C-language object that may take on different values,
and it can only have one such value at a time. How does that fail to
answer your question?
Post by a***@gmail.com
... or whether
its use in 7.17 and 7.21 is significant. Would 7.17 and 7.21 have
<threads.h> is covered by 7.26 in my copy of C2011.
Post by a***@gmail.com
the same normative meaning if 'variable' was replaced by 'object'?
Derek's correct about the normative references. Since C objects, by
definition, "can represent values" (3.15), they all meet that
definition, so in principle, variable should effectively be a synonym
for "object". I don't see anything in 7.17 or 7.26 that's clearly
inconsistent with that interpretation.
--
James Kuyper
FrankHB1989
2015-05-18 17:39:10 UTC
Permalink
Raw Message
Post by a***@gmail.com
The standard seems quite precise in its use of the noun 'variable'.
There is no entry for 'variable' either in the terms list in section 3
(not even as a deprecated term) or the index. Almost always in
normative text, 'variable' is used as an adjective, as in
'variable length array' or 'variable arguments'. 7.6 (fenv.h)
describes certain 'system variables'.
There are however quite a lot of uses of 'variable' (noun) in the
non-normative footnotes, where it seems to mean an object.
Then finally, 7.17 (atomics) uses 'variable' freely in normative
text, and 7.21 (threads) uses 'condition variable'.
So is 'variable' a synonym for 'object with an identifier' or just
'object'? Is an element of an aggregate, a variable? A bit field?
Or does it specifically mean an atomic object - is its use in 7.17
significant, rather than sloppy? Does it need defining in section 3?
I guess the noun "variable" before C11 is avoided intionally thoughout the normative text. The meaning of condition variables introduced by C11 are significantly different, so it seems things are not changed in C11.

As I learned, in general (among different languages), the meaning of this concept is disputed, e.g. https://existentialtype.wordpress.com/2012/02/01/words-matter/ .

Historically, "variable" is a notion of mathematics. The word "variable" basically means the property of relations between names and some other entities being denoted, i.e. the "binding", rather than the "stored value" or something else, can vary in different places on demand.

Therefore it has nothing to do with mutability, until someone invents a system can hold mutable states associated with names and calls them "variables". Note there is still nothing wrong.

However, when more and more people learned "variables", few of them have thought why they are called so. Most of them are neither language lawyers and nor historians, with little interest on reasoning of wording. After they meet a few languages (mostly imperative), they easily infers "variable" is "variable state". This is not true in some other languages. For instance, variable in Haskell is immutable.

Because there are too many people think as that, we cannot just say it is wrong, even it is certainly not reasonable to randomly narrow the extension of a formerly well-known concept.

In C, there is no normative term "variable". Despite naming, the term "object" implements this notion with one more exposed thing: "storage", which effectively models the ability of expressing mutable states. When declared, the identifier is the name of the object. There are no need to define what is a "variable". No need of ISO/IEC 2382 here.
Post by a***@gmail.com
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.
Namely there are "variables" not implemented by "objects" in C++. Thus we need a normative definition. This is still nothing to do with ISO/IEC 2382 even if it is a normative reference of ISO/IEC 14882.

Note C++11 has also condition variables in library clauses. It is quite clear that thay are not variables mentioned above.

To be honest, I don't think this concept is totally clear in C++, and would be worse in C. Is "variable" a name, an identifier, an expression, or otherwise an entity? Each option is more or less plausible according to the traditional meaning of mathematics.

BTW, the term "entity" is defined in Clause 3 of ISO C++ due to the need of One Definition Rule. In ISO C it is not defined normatively, but used several times. This could be a problem.
Loading...