You know, it's just occurred to me...

Janice Caron caron800 at googlemail.com
Sun Dec 2 13:10:25 PST 2007


There's a general expectation in D that for all T, T[] is an array of
T. Well, it's not always true... See,

    const(int)[] a;

does not declare a to be an array of "const(int)" at all. It declares
a to be an array of "const int" (without the parentheses). The
difference is that (under the peculiar syntax we have right now with
D2.008), "const(int)" is mutable (!), wheras "const int" is const - as
demonstrated by the following code.

    const(int) x;
    const int y;
    x = 1; // OK
    y = 2; // Error

Yet we write "const(int)[]", not "(const int)[]". Huh?

So, not only is my expectation that "const(X)" should mean the same
thing as "const X" confounded, but now it turns out that my
expectation that "T[]" means "array of T" is also confounded.

You can just imagine how easy this is going to be to explain to newbies. :-)



More information about the Digitalmars-d mailing list