This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: const warning...


On 04-Jul-2003, Theodore Papadopoulo <Theodore.Papadopoulo@sophia.inria.fr> wrote:
> 
> The idea would be to add a -W flag (yet unnamed)

"-Wmissing-const"?

> that will try to 
> help the user in identifying the places where a const qualifier 
> could be added (this can be for variables and also for methods in 
> C++). This might help a lot in constifying a code (even thought I'm 
> trying to constify from the beginning), or completing the 
> constification of a code.

Given a pointer declaration such as
	
	char * p;

it is far more useful to add a const qualifier on the pointed-to type, i.e.

	char const * p;

rather than adding a const qualifier on the variable's type, i.e.

	char * const p;

Adding "const" on local variable definitions that happen to only be set
once is not especially useful for documentation or maintenance purposes.
But adding "const" on pointer targets is very useful for documentation
and maintenance.  I would much prefer a warning for missing const on
pointer targets than for missing const on variable definitions.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]