Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

question about c

7 views
Skip to first unread message

rabbani...@gmail.com

unread,
Apr 28, 2009, 6:50:27 AM4/28/09
to
What is a variable?

Ian Collins

unread,
Apr 28, 2009, 6:51:53 AM4/28/09
to
rabbani...@gmail.com wrote:
> What is a variable?

Something that can vary.

--
Ian Collins

Richard Heathfield

unread,
Apr 28, 2009, 8:02:18 AM4/28/09
to
rabbani...@gmail.com said:

> What is a variable?

Very often, it is the short questions that are hardest to answer.

The Standard does not define the term "variable", but it does /use/
the term, so let's look at the relevant usages and find out what we
can about variables.

(The Standard also uses the term "variable" in other contexts, such
as "variable number of arguments". I'll try to filter those out,
since they aren't relevant here.)

In this discussion, I will refer only to normative text, not to
examples or footnotes. And in an attempt to forestall arguments,
I'll refer solely to C99.

+---------------------------------------------------+
| 6.8.5.3 The for statement |
| |
| [...] If clause-1 is a declaration, the scope of |
| any variables it declares is the remainder of the |
| declaration and the entire loop, including the |
| other two expressions; [...] |
+---------------------------------------------------+

So we can see that a variable has a *scope*, and can be *declared*.

+---------------------------------------------------+
| 7.6 Floating-point environment <fenv.h> |
| |
| A floating-point status flag is a system variable |
| whose value is set (but never cleared) when a |
| floating-point exception is raised, which occurs |
| as a side effect of exceptional floating-point |
| arithmetic to provide auxiliary information. A |
| floating-point control mode is a system variable |
| whose value may be set by the user to affect the |
| subsequent behavior of floating-point arithmetic. |
+---------------------------------------------------+

And here we see that a variable (or at least a "system variable")
has a *value*.

+---------------------------------------------------+
| F.8.1 Global transformations |
| |
| The flags and modes in the floating-point |
| environment may be regarded as global variables; |
| floating-point operations (+, *, etc.) implicitly |
| read the modes and write the flags. |
+---------------------------------------------------+

(I have often said that there is no such thing as a "global
variable" in C. Here, the normative text flatly contradicts me.
Naturally, I consider the Standard to be flawed here, but of course
that's an uphill argument if ever there was one. In my view, the
term "global variable" is clear as mud, and is unhelpful in forming
an understanding of how C works; the C Standard would do better to
stick to terms like "object" when it means "object" and
"identifier" when it means "identifier", and to refer to specific
scopes and linkages rather than use the woolly and inaccurate term
"global".)

So - here we see that a variable can be global (again, the Standard
fails to define this term, but we might think of it, given the
context, as meaning "having file scope and possibly external
linkage"), and can be used as an operand, at least for certain
operators.

And that's IT. That's all the normative Standard text has to say
about variables. Let's recap:

(a) A variable has a scope.

(b) A variable is (or at least can be) declared.

(c) A variable can have a value.

(d) A variable can be "global", for some meaning of the term
"global" that the Standard fails to spell out.

We'll ignore (d), since it seems to be pretty much covered by (a).

From 6.2.1 we learn that "scope" is a property of *identifiers*.
Therefore, unless someone can demonstrate that some other entity
other than an identifier can also have scope, we may deduce that a
variable is an identifier.

From the definition of "parameter" in 3.15, we can deduce that
objects can be declared, and functions can be declared. From
6.2.1(3) we learn that a label can be (implicitly) declared. From
6.2.1(4) we learn that a type can be declared. I haven't checked
for other declarable esoterica, however, because we know from (c)
that a variable can have a value, which pretty much brings us down
to objects.

From 6.2.1(4) we can also see that an identifier can designate
either of two different entities in the same name space. We deduce
that an identifier does not necessarily uniquely describe an object
- identifiers can be ambiguous (and C provides rules to
disambiguate them).

From this mess, it appears that:

(i) a variable is an identifier;
(ii) a variable is an object;
(iii) the concepts of "identifier" and "object" are distinct.

So perhaps the kindest way to describe "variable" is to refrain from
calling it a pig's breakfast of a concept that has no business
being in the Standard at all, and instead to think of it as an
association of an identifier with an object - a sort of cartouche
that gathers the two ideas together and allows us to consider
aspects of both within a single word.

Very often, it is the short questions that are hardest to answer.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

Eric Sosman

unread,
Apr 28, 2009, 8:21:32 AM4/28/09
to
rabbani...@gmail.com wrote:
> What is a variable?

A star whose brightness (as observed from Earth) changes
as time passes. The discovery of variables was an important
event in scientific thought, as it overturned the Aristotelean
view of the heavens as changeless and perfect.

Some famous variables are Mira (Omicron Ceti) and Algol
(Algorithmic Language).

--
Eric Sosman
eso...@ieee-dot-org.invalid

osmium

unread,
Apr 28, 2009, 8:57:03 AM4/28/09
to
<rabbani...@gmail.com> wrote:

> What is a variable?

Wikipedia is usually an excellent source to answer questions such as that.
If you put
variable wiki
as a search target for Google it will lead you to a nice, well thought out
answer.


James Kuyper

unread,
Apr 28, 2009, 9:55:39 AM4/28/09
to
rabbani...@gmail.com wrote:
> What is a variable?

The C standard uses the term but, almost exclusively as an adjective,
not as a noun. It does not define the term. My personal understanding is
that the term variable refers to a named object. This is a pretty good
match to the definition that is provided by the C++ standard:

"A variable is introduced by the declaration of an object. The
variable’s name denotes the object." (3p6)

The word "variable" is italicized, an ISO convention indicating that
this sentence constitutes the definition of the term.

There are three uses of the term "variable" as a noun in the C standard
that are consistent consistent both with my understanding, and the C++
definition: two in footnotes 41 and 137, and one in 6.5.16.1p4, which is
an example - none of these are in normative text.

Note: the use of 'variable' that Richard Heathfield mentions in
6.8.5.3p1 has been changed to "identifier" in n1256, so apparently other
people agree with his criticism of that usage.

There are two additional uses of 'variable' as a noun in 7.6p1:

"A floating-point status flag is a system variable whose value is set
(but never cleared) when a floating-point exception is raised, which
occurs as a side effect of exceptional floating-point arithmetic to

provide auxiliary information.179) A floating point control mode is a

system variable whose value may be set by the user to affect the
subsequent behavior of floating-point arithmetic."

Now, these variables don't have any name that is known by the user, but
presumably they do (or at least could) have a name known to the
implementation.

Richard Bos

unread,
May 2, 2009, 12:00:11 PM5/2/09
to
Eric Sosman <eso...@ieee-dot-org.invalid> wrote:

> rabbani...@gmail.com wrote:
> > What is a variable?
>
> A star whose brightness (as observed from Earth) changes
> as time passes. The discovery of variables was an important
> event in scientific thought, as it overturned the Aristotelean
> view of the heavens as changeless and perfect.
>
> Some famous variables are Mira (Omicron Ceti) and Algol
> (Algorithmic Language).

Algol is off-topic here. There is no group for it on my server, so maybe
you should try comp.programming.

Richard

Richard Heathfield

unread,
May 2, 2009, 2:34:56 PM5/2/09
to
Richard Bos said:

<snip>



> Algol is off-topic here. There is no group for it on my server, so
> maybe you should try comp.programming.

My server claims to carry comp.lang.algol. I haven't checked to
determine whether it's a genuine group, but it's not impossible.

Mark McIntyre

unread,
May 2, 2009, 3:36:56 PM5/2/09
to
On 02/05/09 19:34, Richard Heathfield wrote:
> Richard Bos said:
>
> <snip>
>
>> Algol is off-topic here. There is no group for it on my server, so
>> maybe you should try comp.programming.
>
> My server claims to carry comp.lang.algol. I haven't checked to
> determine whether it's a genuine group, but it's not impossible.

I'm still not sure whether you both missed the point entirely, or were
being very obscurely humorous....
http://en.wikipedia.org/wiki/Algol_variable

Richard Heathfield

unread,
May 2, 2009, 4:45:12 PM5/2/09
to
Mark McIntyre said:

I figured.

Spiros Bousbouras

unread,
May 2, 2009, 4:49:39 PM5/2/09
to
On 2 May, 20:36, Mark McIntyre <markmcint...@TROUSERSspamcop.net>
wrote:

Given what Eric Sossman said


Some famous variables are Mira (Omicron Ceti) and Algol
(Algorithmic Language).

I think http://en.wikipedia.org/wiki/Algol would be the right link.
As for the right newsgroup, thanks to this OOT excursion I
discovered that there's a whole sci.astro* hierarchy plus
alt.astronomy I never realised that astronomy is so popular.

Mark McIntyre

unread,
May 2, 2009, 5:55:52 PM5/2/09
to
On 02/05/09 21:45, Richard Heathfield wrote:
> Mark McIntyre said:
>
>> On 02/05/09 19:34, Richard Heathfield wrote:
>>> Richard Bos said:
>>>
>>> <snip>
>>>
>>>> Algol is off-topic here. There is no group for it on my server,
>>>> so maybe you should try comp.programming.
>>> My server claims to carry comp.lang.algol. I haven't checked to
>>> determine whether it's a genuine group, but it's not impossible.
>> I'm still not sure whether you both missed the point entirely, or
>> were being very obscurely humorous....
>
> I figured.

You made a likeness, calculated with numbers or adorned? Which one?

Richard Heathfield

unread,
May 2, 2009, 7:14:16 PM5/2/09
to
Mark McIntyre said:

> On 02/05/09 21:45, Richard Heathfield wrote:
>> Mark McIntyre said:
>>

<snip>

>>> I'm still not sure whether you both missed the point entirely,
>>> or were being very obscurely humorous....
>>
>> I figured.
>
> You made a likeness, calculated with numbers or adorned? Which
> one?

Mu.

Preston

unread,
May 5, 2009, 1:24:51 PM5/5/09
to
On 2009-04-28 04:50:27 -0600, rabbani...@gmail.com said:

> What is a variable?

http://www.lmgtfy.com/?q=variable

0 new messages