Logical const

Bruno Medeiros brunodomedeiros+spam at com.gmail
Thu Dec 2 09:59:22 PST 2010


On 01/12/2010 21:09, Steven Schveighoffer wrote:
> On Tue, 30 Nov 2010 16:53:14 -0500, Walter Bright
> <newshound2 at digitalmars.com> wrote:
>
>> Steven Schveighoffer wrote:
>>> If you find the above unsurprising, you are in the minority. I find
>>> it surprising, and invalid that anyone would write code this way.
>>> People simply just don't do that normally. It's just written to
>>> demonstrate a point that the compiler does not guarantee anything via
>>> const, it's guaranteed by convention. The compiler simply helps you
>>> follow the convention.
>>
>> Ok, I see what you mean now. Your code is relying on there being a
>> mutable alias of the same object.
>>
>> This is not surprising behavior. It is explicit in how const is
>> defined. It makes sense that const does not have immutable behavior,
>> because otherwise there wouldn't be both const and immutable type
>> constructors.
>>
>> You're wrong in saying the compiler doesn't guarantee anything with
>> const. I listed the things it does guarantee.
>
> The literal guarantee is that things aren't modified through that
> reference.

So now you do agree that (D's) const does provide guarantees, right?


-- 
Bruno Medeiros - Software Engineer


More information about the Digitalmars-d mailing list