Dynamic Arrays & Class Properties

Bill Baxter wbaxter at gmail.com
Thu Aug 28 17:50:05 PDT 2008


On Thu, Aug 28, 2008 at 3:39 PM, Denis Koroskin <2korden at gmail.com> wrote:
>
> There is also a final in D1:
>
> final char[] test = "hello";
> test.length = 4; // Error: cannot modify final variable 'test'
> test = "world";  // Error: cannot modify final variable 'test'
>
> but it doesn't work very well, too:
> test[0] = '!'; // success

I think that's correct behavior.  'final' is supposed to be a kind of
head-const, no?  So all the bits of 'test' on the stack are immutable,
but the bits on the heap are mutable.

> and everything compiles "fine" with -v1 switch (what does it do?):
> final char[] test = "hello";
> test.length = 4; // no error

If I'm not mistaken, -v1 means act like some antiquated version of the
D compiler that no one cares about any more.

--bb


More information about the Digitalmars-d-learn mailing list