D const design rationale

Kristian Kilpi kjkilpi at gmail.com
Sun Jun 24 09:48:17 PDT 2007


On Sun, 24 Jun 2007 19:03:37 +0300, Sean Kelly <sean at f4.ca> wrote:

> Kristian Kilpi wrote:
>>  What if we drop out the 'invariant' keyword, and simply define that  
>> aliasing
>> is illegal (by default) and result in undefined behaviour?
>
> That would pretty much invalidate the use of slicing, which is one of  
> the most powerful features of the language.
>
>
> Sean

On Sun, 24 Jun 2007 19:03:37 +0300, Sean Kelly <sean at f4.ca> wrote:
> Kristian Kilpi wrote:
>>  What if we drop out the 'invariant' keyword, and simply define that  
>> aliasing
>> is illegal (by default) and result in undefined behaviour?
>
> That would pretty much invalidate the use of slicing, which is one of  
> the most powerful features of the language.
>
>
> Sean

You mean that a programmer has been slicing arrays around so much that  
(s)he cannot
know (be sure) if two arrays/slices overlap? ;)

But, if the slices do overlap, and one of them is modified, wouldn't that
(very likely) be a bug anyway (that is, when you do that 'by accident')?
-> The same aliasing problem?

For instance, 'memcpy()' does not work correctly if the destination and  
source overlap.
You have to use 'memmove()'.

(Constant aliasing would be ok of course. E.g. "void f(const int *a, const  
int *b);  f(&v, &v);")



More information about the Digitalmars-d mailing list