What is the difference between...

Sean Kelly sean at f4.ca
Sat Sep 8 07:32:42 PDT 2007


Nathan Reed wrote:
> Bruno Medeiros wrote:
>> This 'head'/'tail' Robert has been mentioned seems related. Seems the 
>> term 'head' is the same as 'top-level value'.
>>
> 
> Yes.  The 'final' storage class makes the head const, which as you've 
> pointed out can't be done with the 'const' type constructor.  So:
> 
> const(int)* x;        // mutable pointer to const int
> const(int*) x;        // mutable pointer to const int
> final const(int)* x;  // const pointer to const int
> final const(int*) x;  // const pointer to const int
> 
> (This is described on the lecture slides from the conference, so I'm not 
> sure if it is implemented quite this way yet.)
> 
> However, there is also still the 'const' storage class (as distinct from 
> the type constructor)...it's not clear to me exactly how that differs.

The 'const' storage class is essentially the same as 'const' works in D 
1.0 now.  The advantage being that the compiler can place the data in 
ROM or simply use them as compile-time constants and not store them at all.

> Does anyone else think this is much too confusing?  I realize D const is 
> a different animal from C++ const, but it seems to be badly in need of 
> some simplification.

I do.  In fact, as much as I hate to say it, I actually find the C++ 
declarative form easier to visually parse.  The new head/tail idea for D 
2.0 is better than what we have now however, and I think we can do 
better still (though I don't have any suggestions yet regarding how).


Sean



More information about the Digitalmars-d mailing list