const again

Walter Bright newshound1 at digitalmars.com
Thu Dec 6 21:16:49 PST 2007


Christopher Wright wrote:
> Walter Bright wrote:
>> Christopher Wright wrote:
>>>> I've given up on tail const in any of its forms. The new regime has 
>>>> no tail const, no head const, it's just const, and fully transitive 
>>>> const at that.
>>>
>>> So if I have:
>>> const(Foo)* t;
>>> the pointer is const and points to a const Foo?
>>
>> No, it is a mutable pointer to a const Foo. A const pointer to a const 
>> Foo would be:
>>     const(Foo*) t;
>>
>>> Will that fail?
>>
>> Yes, because T[] will be the same thing as const(Foo)[]. Hiding it 
>> behind an alias and a template won't change that <g>.
> 
> So why do arrays take their const status from their elements when 
> pointers don't?

??? I think there's a misunderstanding here on what arrays are. Arrays 
consist of a pointer/length pair. As far as const goes, they are just 
like pointers.



More information about the Digitalmars-d mailing list