any news on const/invariant?

Walter Bright newshound1 at digitalmars.com
Mon Nov 26 16:33:35 PST 2007


Steven Schveighoffer wrote:
> "Walter Bright" wrote
>> Derek Parnell wrote:
>>> On Mon, 26 Nov 2007 14:11:25 -0800, Walter Bright wrote:
>>>> 2) no more 'head const' or 'tail const', it's all just 'const'
>>> Does that mean that if X is const then neither the bits in X and the bits
>>> referenced by X can be modified (though the X symbol)?
>> Const and invariant are transitive. C++ const is not transitive, leading 
>> to programmers establishing a *convention* for transitive const. But it 
>> being an unenforced convention means it is not reliable.
> 
> Before, I could declare an array of const characters.  Essentially, the 
> array structure could be modified, but the characters pointed to by the 
> array could not.
> 
> i.e.
> 
> const(char)[] myString = "hello";
> 
> However, in this case, I could slice my string like so
> 
> myString = myString[0..4] // set to "hell"
> 
> The way you are talking this is no longer possible?

It still works.


> Because now I can only 
> have a fully const array which means you cannot change the pointer in the 
> array?

A "fully const array" would be declared as:
	const(char[]) myString;
or just:
	const char[] myString;



More information about the Digitalmars-d mailing list