const

Benji Smith benji at benjismith.net
Fri Mar 28 12:26:54 PDT 2008


Sean Kelly wrote:
> I think the need for const vs. invariant in D 2.0 is that the compiler isn't
> smart enough to know when the referenced data should actually never
> change, and because a bunch of interesting optimizations are available
> when the data really doesn't ever change, we have a keyword to hint to
> the compiler that this is true.

If the compiler can't actually detect mutation of const values, then how 
will it enforce const correctness? Is the 'const' keyword just a fancy 
compiler-enforced form of documentation?

> It's much like "register" in C/C++.

I was thinking the same thing myself, which is one of the reasons I 
dislike the constness being part of the type. In C++ "register" isn't 
part of the type system. It's just an optimization hint.

--benji smith



More information about the Digitalmars-d mailing list