Extended Type Design.

Walter Bright newshound at digitalmars.com
Tue Mar 20 11:43:08 PDT 2007


Andrei Alexandrescu (See Website For Email) wrote:
> I think the shock will be mollified by the explanation that const is for 
> the stuff "before the star" and final is for the stuff "after the star".
> 
> const char *const s = "hello"; // C++
> 
> Many C++ programmers complain about this syntax, finding it silly.

I also have to always stop and think about what it means. Const in C++ 
actually has 3 distinct meanings, and which is in force depends on the 
context.

In my discussions about this with C++ programmers, even C++ compiler 
implementors, very, very few understand just what is going on with C++ 
const. I think a lot of the confusion here about const is coming from 
the misunderstandings engendered by the C++ mechanism.

What the D proposal does is identify those 3 distinct meanings, and make 
them distinct and individually controllable. This should also, in the 
long run, make it more understandable once one is able to get past the 
wacky confusion that is C++ const.

It also gives those who care about const-correctness the mechanism to 
control precisely what they need, and it can even help the optimizer 
generate better code. (C++ const is worthless for generating better code.)



More information about the Digitalmars-d mailing list