I just got it! (invariant/const)

Georg Wrede georg at nospam.org
Wed Apr 9 10:32:51 PDT 2008


Steven Schveighoffer wrote:
> 
> There are interesting puzzles that I'm not sure how they will be solved. 
> For example:
> 
> pure int f()
> {
>    char[] c = new char[15];
>    c[0] = 'h'; // does this compile?
> }
> 
> Does c need to be invariant to access members of the array?  Clearly from 
> this code, you can see that c is private to f.  But under the rules, the 
> data c references is not invariant, and so should be inaccessible.  How will 
> the compiler make this distinction?

Before commenting on the rest,

to me it is obvious that c is solely owned by f (because no references 
to c can exist outside of f), and therefore c is considered internal to 
f, so it's legal.



More information about the Digitalmars-d mailing list