Well I would still insist that generally it means READ-ONLY.
Especially that you so nicelly explained that in the second part of
your post
There is a problem here: the word "it" refers to -- what?
Here is the original subject line:
Const expression
(complete with uppercase "C").
Here is the original *text* of the original article:
Can anyone just help me with what exactly is constant
expression. I read the section on Constant expression
in K&R2. i am not fully clear with it.
The thing that means "read-only", in C, is the type qualifier
"const".
A constant-expression, in C, has nothing to do with the "const"
keyword. (C++ is different, as usual.
)
And yes. I meant machine level registers, like in embedded
programming where const and volatile is used very often.
So, clearly, when you used the word "it" above, you meant the
"const" qualifier, as in "const and volatile" (and in C99, the
new "restrict" qualifier).
Unfortunately, I believe the original poster was not asking about
"const", but rather about constant-expressions.
For a complete definition of constant-expression, one must refer
back to the relevant standard (C89 or C99; there are some minor
differences between the two). The collection of "things that are
constant-expressions" is somewhat peculiar -- for instance, after:
enum { THREE = 3 };
const int FOUR = 4;
the following *are* constant-expressions:
3
THREE
4
but:
FOUR
is not a constant-expression. Moreover, most operators, applied
to something that is a constant-expression, produce a new
constant-expression with the obvious value:
THREE + 4
is a constant-expression and is just 7. Yet the comma operator,
which evaluates its left-side expression and then discards the
value and then evaluates its right-side expression and produces
that as its value, is never a constant-expression, even if both
operands are constant:
1, 2 /* not a constant-expression */
The latter actually avoids some common errors:
int M[5, 7]; /* oops, programmer "meant" int M[5][7] */
int f(void) { ... }
should generally draw a diagnostic, because (5, 7) is not a
constant-expression. There is a somewhat odd sentence in the
Standards:
An implementation may accept other forms of constant expressions.
Exactly what this means is not clear to me, since implementations
*can* *always* do stuff "beyond the standard" as long as they
provide whatever diagnostics are required by the standard. That
is, after printing something like:
warning: 5,7 is not a Standard-conforming constant-expression
any C compiler can go on and treat it as if you had just written
7. So what is the point of this extra sentence?