What's the diff between immutable and const?

Simen kjaeraas simen.kjaras at gmail.com
Thu Apr 22 02:32:59 PDT 2010


XCPPCoder <xcelsior at jupitor.com> wrote:

> What's the diff between immutable and const?

Basically, const means 'I can't change this', while immutable means 'nobody
will change this'.
The idea is that const is a guarantee given by a function, while immutable
is a guarantee for the whole program. Also, immutable opens up optimization
possibilities, as you can safely assume the data is not going to change
under you. That means read once, and no locks necessary.

-- 
Simen


More information about the Digitalmars-d-learn mailing list