relax inout rules?

Steven Schveighoffer schveiguy at yahoo.com
Wed Dec 14 10:06:24 PST 2011


On Tue, 13 Dec 2011 00:57:28 -0500, Jesse Phillips  
<jessekphillips+d at gmail.com> wrote:

> On Mon, 12 Dec 2011 13:56:43 -0500, Steven Schveighoffer wrote:
>
>> The example we were discussing on the other thread was this:
>>
>> void foo(ref inout(int)* a, inout(int)* b) { a = b;}
>
> Is this just so it is easier to explain inout and won't have to explain
> that const will do the same thing? Or does this actually do something
> using const there doesn't?
>
> void f(ref const(int)* a, const(int)* b) {a = b; }
> void main() {
>    const(int)* a;
>    immutable(int)* b;
>    auto c = (new int[](5)).ptr;
>    f(a, c);
>    f(b, c); //test.d(7): Error: cast(const(int)*)b is not an lvalue
> }

Yes it does:

immutable(int)* d;

foo(b, d); // OK
f(b, d); // error (as you cited above).

-Steve


More information about the Digitalmars-d mailing list