On Thursday, 3 July 2014 at 21:06:12 UTC, Jet wrote:
There, how to distinguish between const and immutable? thank
you~:)
/**
"Const types are like immutable types, except that const forms
a read-only view of data. Other aliases to that same data may
change it at any time. "
"Any data referenced by the const declaration cannot be changed
from the const declaration, but it might be changed by other
references to the same data. "
**/
Can sample code, please?
When you replace 'immutable' with 'const' in your sample code,
then there is no undefined behaviour, and no cast is needed.
void foo(const int* x, int* y) {
bar(*x); // bar(3)
*y = 4; // perfectly fine
bar(*x); // bar(4)
}
void main()
{
int i = 3;
foo(&i, &i); // no cast
}