Jonathan M Davis Wrote: > In C++, I tend to declare all local variables const when I know that they > aren't > going to need to be altered. I'd like to something similar in D. However, D > has > both const and immutable. I can see clear differences in how const and > immutable > work with regards to function parameters and member variables, but it's not > as > clear with regards to const and immutable. > > So, the question is: what are the advantages of one over the other? > Specifically, > my concern is how likely compiler optimizations are. Does using immutable > make > compiler optimizations more likely? Or would const do just as well if not > better? Or is dmd smart enough that it really doesn't matter if you use const > or > immutable on local variables which never change? > > - Jonathan M Davis
Doesn't immutability imply static storage? I also thought, it's a way to force CTFE.