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 documentation.

In addition to the excellent responses in this thread, this is how I like to describe the semantics between const versus immutable references (including pointers) on a function interface:

- const reference or pointer parameter: "I will not modify your data."

- immutable reference or pointer parameter: "I demand data from you that nobody will modify."

When the semantics are described that way, they are not related at all: One is a promise to the caller, the other is a request from the caller.

Ali

Reply via email to