On Thursday 17 January 2008 11:51:49 pm Giacomo Catenazzi wrote:
The restrict keyword controls aliasing, to be exact. And I'm skeptical that
inserting const there would do anything at all.
I must ask what relationship you think the const keyword has to compiler
optimizations. I know of none, and I've yet to see that keyword cause any
difference in the resulting assembly. It forces you to make your code clean
and well-structured, but that's about it.
Of course, it would be an interesting experiment to potentially redefine the
const keyword to have stronger semantics, such as having the compiler assume
that a function taking a const pointer argument will not modify the memory
the pointer points to, and thus saving itself a memory load in the caller
after the function executes, as long as the data is not global. I imagine
that this would lead to some simple and measurable optimizations, all the
while (this is where I get into hand-waving territory) breaking a minimum
amount of code in current existence.
But that is emphatically not how C is currently defined, and you're basically
inventing an entirely new language... C2009 perhaps? :-)
-- Vadim Lobanov
--