immutable/mutable aliasing

2014-07-03 Thread Jet via Digitalmars-d-learn
void foo(immutable int* x, int* y) { bar(*x); // bar(3) *y = 4; // undefined behavior bar(*x); // bar(??) } ... int i = 3; foo(cast(immutable)i, i); -- In the 2.065 version, I can compile. But that is not in the documentation.

Re: immutable/mutable aliasing

2014-07-03 Thread Jet via Digitalmars-d-learn
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

Re: immutable/mutable aliasing

2014-07-03 Thread anonymous via Digitalmars-d-learn
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

Re: immutable/mutable aliasing

2014-07-03 Thread anonymous via Digitalmars-d-learn
On Thursday, 3 July 2014 at 20:43:33 UTC, Jet wrote: void foo(immutable int* x, int* y) { bar(*x); // bar(3) *y = 4; // undefined behavior bar(*x); // bar(??) } ... int i = 3; foo(cast(immutable)i, i); -- In the 2.065 version, I can compile. But that is not in

Re: immutable/mutable aliasing

2014-07-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 03, 2014 at 09:06:11PM +, Jet via Digitalmars-d-learn 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

Re: immutable/mutable aliasing

2014-07-03 Thread Jet via Digitalmars-d-learn
Thank you all. These answers are very detailed. I think I learned a lot.

Re: immutable/mutable aliasing

2014-07-03 Thread Jet via Digitalmars-d-learn
Awesome!!! Thank you so much!

Re: immutable/mutable aliasing

2014-07-03 Thread Ali Çehreli via Digitalmars-d-learn
On 07/03/2014 01:43 PM, Jet wrote: void foo(immutable int* x, int* y) { bar(*x); // bar(3) *y = 4; // undefined behavior bar(*x); // bar(??) } ... int i = 3; foo(cast(immutable)i, i); -- In the 2.065 version, I can compile. But that is not in the