Proposal - Revised Syntax for const and final

Nathan Reed nathaniel.reed at gmail.com
Sat Sep 8 10:32:32 PDT 2007


Janice Caron wrote:
> All I know for sure is that the existing D2.0 scheme is too confusing.
> The fact that
> const(int**) s;
> const(int*)* s;
> both mean the same thing is highly counterintuitive. If we're stuck
> with the current scheme, I would prefer that the first version be
> declared a compile-time error (since s can in fact be assigned).

Agree.  And for what it's worth, I agree with you about losing the 
storage-class version of const.  I also agree with using some different 
syntax to denote tail-constness, since having const(S) for S a struct 
mean that S's members are mutable is unintuitive.

Ultimately, though, I think constness is always going to work 
differently for value types than reference types.  After all, the whole 
reason we have both kinds of types is that they are both useful, and 
have different semantics - hence we shouldn't try *too* hard to pretend 
they're the same thing. (A pointer to a struct should behave the same as 
a reference to an object though.)

Thanks,
Nathan Reed



More information about the Digitalmars-d mailing list