Related articles |
---|
feature wanted: detect missing 'const' john_reiser@rainbow.mentorg.com (1994-03-16) |
Re: feature wanted: detect missing 'const' bill@amber.csd.harris.com (1994-03-23) |
Alternatives to const. mps@dent.uchicago.edu (1994-03-24) |
Re: Alternatives to const. hbaker@netcom.com (1994-03-25) |
Re: feature wanted: detect missing 'const' Mark.Lomas@cl.cam.ac.uk (1994-03-25) |
Re: Alternatives to const. jan@neuroinformatik.ruhr-uni-bochum.de (1994-03-28) |
partial const'ness (was feature wanted: detect missing 'const') dfb@beech.CS.Berkeley.EDU (1994-03-28) |
[1 later articles] |
Newsgroups: | comp.compilers |
From: | john_reiser@rainbow.mentorg.com (John Reiser) |
Keywords: | C++, lint |
Organization: | Compilers Central |
Date: | Wed, 16 Mar 1994 16:30:14 GMT |
Dear C/C++ compiler writer:
Please add a feature that emits a message whenever the declaration of a
local scalar variable could have had the type qualifier 'const', but did
not. This will be a great help to developers and maintainers who use your
compiler. Effective use of 'const' dramatically reduces the effort
required to understand code, because 'const' factors out flow of control
and the passage of time. A message such as
line 423: warning: missing 'const' in declaration of <foo>
will be even more useful than similar messages that many compilers emit
about local variables that are unused, or read before written.
The "missing 'const'" message is intended to communicate to the user from
the compiler, "I [the compiler] would not have complained if you had
supplied 'const'." Obviously, such a message cannot be given until the
end of the scope in which the variable is declared. A single bit in the
symbol table is sufficient to keep track of whether there would have been
any complaints about 'const'. I write compilers myself, and I understand
how precious are bits in the symbol table; please make room for one more.
C++ compilers should treat declaration with initialization, and assignment
at declaration, equivalently. The statements
int a(5);
int b = 6;
should both be eligible for the "missing 'const'" message, as long as
there are no further writes to either 'a' or 'b'.
More than one 'const' may appear in the declaration of a pointer:
int const *const pi = fpic(7, 4);
but the "missing 'const'" message should apply only to the 'const'
immediately adjacent to the variable name.
A "missing 'const'" message would have saved me from at least three bugs
in the past year. Please add such a message to your compiler.
Sincerely yours,
John F. Reiser john_reiser@MentorG.com
Mentor Graphics Corporation
8005 SW Boeckman Road
Wilsonville, OR 97070 USA
+1 503 685 7000 x3548
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.