D const design rationale

Christian Kamm kamm.incasoftware at shift-at-left-and-remove-this.de
Wed Jun 27 13:40:19 PDT 2007


> I think that invariant-as-storage-class vs. const-as-storage-class is a
> false dichotomy, and also that they are incorrectly associated with the
> completely different type-constructors, const() and invariant().

I totally agree. It took me a while to accept that

const int i = 1; 
const(int) j = 1;

mean something totally different. Especially since for function parameters

void foo(const int* p);
actually is the same as
void foo(const(int*) p);

I think it'd be easier to understand if compile time constants used a
different keyword altogether and 'const type' was always the same
as 'const(type)', not just in function parameter declarations.

Christian



More information about the Digitalmars-d mailing list