const in dmd v2.011

Derek Parnell derek at nomail.afraid.org
Wed Feb 20 16:44:14 PST 2008


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. 
 
>> ** 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. 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?

Also the forms 'const const(X)[]', 'const const(X[])', and 'const(X[])'
appear to be synonymous, another way to confuse people.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
21/02/2008 11:22:35 AM


More information about the Digitalmars-d-learn mailing list