This is the mail archive of the
mailing list for the GCC project.
Re: why are we not using const?
On 6/29/06, Kaveh R. Ghazi <email@example.com> wrote:
> Notice that the value of the parameter "b" is never changed in the
> function body. Consequently, if the current optimizers cannot figure
> that simple cases out (where "b" is not annotated const), then the
> optimizers in deficient in that respect. That is the point.
> -- Gaby
I agree that the compiler should/could be better at optimizing.
However my feeling is that 'const' is more important as documentation
and enforcement of APIs rather than an optimization hint. From this
perspective, what "b" points to not getting changed is more important
to the caller than whether the function body changes the value of "b"
itself, since the caller doesn't see the latter.
I'd like to do for tree and rtx what I did for const char *, namely
constify those tree/rtx functions that aren't supposed to modify their
arguments. This would require introducing the const_tree and
const_rtx typedefs Tristan suggested.
But with C language constructs you cannot assume that an object
passed to a function via a const pointer is not modified. So, there
is no real "const" regarding to objects pointed to. Consider
void foo(const int *i)
int *k = (int *)i;
*k = 0;
int i = 1;
should return 0, not 1.
Something for stage1, obviously.
Kaveh R. Ghazi firstname.lastname@example.org