|feature wanted: detect missing 'const' email@example.com (1994-03-16)|
|Re: feature wanted: detect missing 'const' firstname.lastname@example.org (1994-03-23)|
|Alternatives to const. email@example.com (1994-03-24)|
|Re: feature wanted: detect missing 'const' Mark.Lomas@cl.cam.ac.uk (1994-03-25)|
|Re: feature wanted: detect missing 'const' firstname.lastname@example.org (1994-03-29)|
|From:||email@example.com (Bill Leonard)|
|Organization:||Harris CSD, Ft. Lauderdale, FL|
|Date:||Wed, 23 Mar 1994 16:12:16 GMT|
firstname.lastname@example.org (John Reiser) writes:
>[have compiler warn when const could have been used but wasn't]
Actually, I've felt for some time that 'const' was actually the wrong
concept, at least for formal arguments of functions. What I would prefer
to see is a 'nonconst' keyword for formals, and have the compiler *assume*
const unless specifically declared nonconst.
This would solve the above problem, but more generally. What it does is
force the programmer to say "I intend to modify this argument" if, in
fact, the argument is to be modified.
The problem I have with const is exactly what John is complaining about:
you can't tell when you *could* have said const but didn't. This becomes
a significant problem when someone writes a library and is rather sloppy
about putting const on arguments to the library routines. Then Joe
Programmer, who has been very careful to put const on all his arguments,
comes along and tries to call one of those library routines and pass it
one of his const parameters. "Hold on", says the compiler, "you're
casting away const." Of course, Joe knows that the library routine
doesn't *really* modify the argument, it just failed to put const on it.
Of course, it's really too late for C and C++ to get this right. But
maybe some future language could.
Harris Computer Systems Division
2101 W. Cypress Creek Road
Fort Lauderdale, FL 33309
Return to the
Search the comp.compilers archives again.