identic ref/inout parameter
Regan Heath
regan at netmail.co.nz
Fri Sep 14 03:49:56 PDT 2007
Regan Heath wrote:
> Wilhelm wrote:
>> Who do I determine in a function (probably with a assert statement)
>> that the function with more the one ref/inout parameters of the same
>> type are not called with the same variable like:
>>
>> private import std.stdio;
>>
>> int main(char[][] args)
>> {
>> int i=3;
>> test( i,i,i,i);
>> return 0;
>> }
>>
>>
>> void test(ref int r1, ref int r2, inout int i1, inout int i2)
>> {
>> writefln (" Ref: r1=%d r2=%d", r1, r2);
>> writefln (" InOut: i1=%d i2=%d", i1, i2);
>> r1 += 2;
>> writefln ("r1 += 2; Ref: r1=%d r2=%d", r1, r2);
>> writefln ("r1 += 2; InOut: i1=%d i2=%d", i1, i2);
>> i2 += 2;
>> writefln ("i1 += 2; Ref: r1=%d r2=%d", r1, r2);
>> writefln ("i1 += 2; InOut: i1=%d i2=%d", i1, i2);
>> }
>>
>> !! That may cause interesting results !!
>
> Maybe...
>
> assert(&r1 != &r2);
> assert(&r1 != &i1);
> assert(&r1 != &i2);
> assert(&r2 != &i1);
> assert(&r2 != &i2);
> assert(&i1 != &i2);
It's a pity that this doesn't work:
assert(r1 is r2);
..etc..
Regan
More information about the Digitalmars-d-learn
mailing list