Re: feature wanted: detect missing 'const' (Bill Leonard)
Wed, 23 Mar 1994 16:12:16 GMT

          From comp.compilers

Related articles
feature wanted: detect missing 'const' (1994-03-16)
Re: feature wanted: detect missing 'const' (1994-03-23)
Alternatives to const. (1994-03-24)
Re: feature wanted: detect missing 'const' (1994-03-25)
Re: feature wanted: detect missing 'const' (1994-03-29)
| List of all articles for this month |

Newsgroups: comp.compilers
From: (Bill Leonard)
Keywords: C++, lint
Organization: Harris CSD, Ft. Lauderdale, FL
References: 94-03-064
Date: Wed, 23 Mar 1994 16:12:16 GMT (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.

Bill Leonard
Harris Computer Systems Division
2101 W. Cypress Creek Road
Fort Lauderdale, FL 33309

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.