fir said:
It is sad to say so but there is some real and terrible stupidnes in
c99. When i wrote programs in c (and I am involved c user) I just use
const int for array boundaries but in c99 (and some previous too,
terribly) it will not compile (see for example
http://stackoverflow.com/questions/1712592/variably-modified-array-at-file-scope
) It is terribly wrong thing for ppl who just wants to use const int
to this purposes and not to use preprocesor - as I do. It is terribly
stupidness in my opinion, it have to be changed.
C is not, never has been, and never will be a 100% cleanly designed
language. Its own creator, Dennis Ritchie, wrote that "C is quirky,
flawed, and a tremendous success."
It has evolved over decades from earlier versions, and from earlier
languages (B, BCPL), and most updates to the language have carefully
maintained (mostly) backward compatibility, to avoid breaking existing
code.
Personally, I agree that it would be nice if C treated const definitions
with constant initializers the way C++ does, so that given
const int answer = 42;
answer would be a constant expression, and I would support such a
change in a future revision. Kenneth Brody pointed out a case where
such a change could break existing code:
===== file1.c
const int table_max = 100;
===== file2.c
extern const int table_max;
This could probably be worked around by making the definition introduce
a constant expression *and* a read-only object. Or, I suppose, the
commitee could decide that it's ok to break existing code in this case,
though that's probably unlikely.
But such a change would require some significant work to define its
behavior in *all* cases, followed by changes to all conforming C
implementations.
I suspect the committee would hesitate to make such a change when there
are already ways to do this, namely:
#define table_max 100 /* should probably be TABLE_MAX */
and
enum { table_max = 100 };
(The latter has the drawback that it works only for constants of
type int.)
I know you've said that you dislike the preprocessor, but you can't
reasonably expect the committee to reject a solution that's been
in common use for decades, and that works perfectly well, because
some guy named "fir" doesn't like it (no offense intended).
Major revisions of the C standard have been issued in 1989/1990,
1999, and 2011. Assuming that new revisions are produced on a
similar schedule, we can expect a new one in 2021 or so. The best
case scenario for the change you advocate is that the committee
spends time between now and 2021 nailing down its definition,
followed by at least several years before implementers fully support
the new standard. You'll then be able to use the new feature --
but only if your code doesn't need to be compiled with pre-C2021
compilers.
So you can either spend the next decade complaining that C's lack
of this feature is "stupid", or you can grit your teeth and use an
enum or #define.
Incidentally, posting in comp.lang.c that this is "stupid"
is definitely not the best way to get this change to happen.
comp.std.c, which discusses the C standard (as opposed to the
langauge defined by that standard) would be better, but even it
has no official standing with the committee, though a few members
do hang out there. (Check the group's history before posting;
it's likely that this idea has been proposed there before.)
And telling the committee that their work is "terribly stupidness"
will not get you anywhere.
And please either use something other than Google Groups to post here,
or clean up the double-spacing it imposes on quoted text before clicking
"send".