Logical const

Simen kjaeraas simen.kjaras at gmail.com
Mon Nov 29 14:21:27 PST 2010


Steven Schveighoffer <schveiguy at yahoo.com> wrote:

> Except the language says what results from your code (casting away const  
> and then mutating) is undefined behavior.  This means all bets are off,  
> it can crash your program.  I'm unsure how the compiler could take that  
> route, but that's what's in the spec.
>
> Maybe because of the way const works, it never really is undefined, but  
> there will always be that loophole.

The thing is, immutable is implicitly castable to const, and immutable
data could be stored in write-protected memory. Apart from that, I believe
it is safe to cast away const.

-- 
Simen


More information about the Digitalmars-d mailing list