www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - const vs immutable

reply Sean Eskapp <eatingstaples gmail.com> writes:
In cases where they are the same, for instance declaring:
const int x = oldX + 5;

vs

immutable int x = oldX + 5;

Or in non-class, non-array function parameters, does it make a difference
which is used?
Jan 18 2011
parent Jesse Phillips <jessekphillips+D gmail.com> writes:
Sean Eskapp Wrote:

 In cases where they are the same, for instance declaring:
 const int x = oldX + 5;
 
 vs
 
 immutable int x = oldX + 5;
 
 Or in non-class, non-array function parameters, does it make a difference
 which is used?

Use immutable, it documents the type better. And const items cannot be used as immutable parameters (value types don't have such restriction).
Jan 18 2011