const in dmd v2.011
Jason House
jason.james.house at gmail.com
Wed Feb 20 18:58:48 PST 2008
Derek Parnell wrote:
> On Wed, 20 Feb 2008 19:03:56 -0500, Jason House wrote:
>
>> It seems like you may have read some very early D 2.x docs on const and
>> not
>> read the later D 2.x docs. The const design has changed a lot.
>
> Thanks Jason. I know that keeping up with the changes in const theory and
> practice is a full time job in itself ;-) but I had been aware of these
> later tweaks.
>
>> Derek Parnell wrote:
>>> Observations:
>>> ** It appears that there is no practical difference between 'const(C) c'
>>> and 'const C c'.
>>
>> This is the definition of transitive const.
>
> Yes it is. What I was bring to attention is the potentially confusing
> syntax options that are now available.
I don't see the confusion. I've previously argued that "const(C) c"
and "const C c" should mean the same thing. The whole distinction between
a type and a storage class seemed foreign and strange to me.
>>> ** It appears that 'const(char[])' and 'const const(char)[]' are
>>> equivalent and also not implemented well (or the error messages are just
>>> bad).
>>
>> const(char)[] means the char's within the array can't be changed, but the
>> array itself can change (ie. length changes, concatenation)
>
> Yes, I know what it means.
Sorry. It's tough to know what people know, and it's usually best to
elimate the simple stuff first ;)
> Again what I'm bring attention to is the
> confusing nature of this syntax.
>
> const(char) X; // 'X' is const.
> const(char)[] X; // 'X' is not const.
>
> also this ...
>
> const(char)* k; // 'k' is a mutable pointer to immutable data.
> const(char*) l; // 'l' is an immutable pointer to immutable data.
>
> The forms 'const(char)[]' and 'const(char)*' ignore transitivity while
> other forms enforce it. It could be confusing, no?
I've already admitted that I'm biased :) It seems easy to explain to me:
* Anything inside parenthesis is constant
* Const is transitive. Any data access through a const reference is const.
* "const T t" is the same as "const(T) t"
> Also the forms 'const const(X)[]', 'const const(X[])', and 'const(X[])'
> appear to be synonymous, another way to confuse people.
I totally agree with that. Literally typed like that seems like it should
be illegal. I can imagine complex cases where something like that should
be legal... eg: alias const(X) Y; const Y z;
More information about the Digitalmars-d-learn
mailing list