Const warning? (was: Re: [Patch] More redundant...)

Paolo Carlini pcarlini@unitus.it
Mon Apr 21 02:21:00 GMT 2003


[discussion moved to gcc]

Gawain Bolton wrote:

> These patches to add "const" make me wonder if the compiler couldn't 
> help us.
>
> I thinking about a warning for variables which the compiler can see 
> are not modified.   Something like:
>
>    Warning: Variable x should be const.
>
> Is this possible?  Could this be useful?

Hi Gawain (by the way those patches mainly remove some NULL pointer 
checks, only secondarily const-ify variables).

I find your question interesting: as for many other warnings of this 
kind (unreachable code, uninitialized variables, and so on) how many 
such warnings would be missed or spuriously emitted would constitute a 
good testbed for the optimizers of the compiler. Ideally the code 
generated would be identical with and without const qualifiers but we 
all know that in the real world this is not the case!

Ideas from the compiler people???

Paolo.



More information about the Gcc mailing list