[chuck-users] Passing classes to functions

Adam Tindale adamtindale at hotmail.com
Fri Oct 2 03:38:27 EDT 2009


Hi All,

I was doing some work and created some bugs that I ironed out when I
discovered something: when non-primitive types are passed to functions
they are passed by reference and not by value! I include a test so you
can see what I mean.

I hope somebody find this useful.

--art

class test{
 0 => int val;
}

test obj1;
// obj2 is a reference to obj1
test obj2 @=> obj1;

<<< obj1.val , "original object">>>;
<<< obj2.val , "reference to original">>>;

2 => obj2.val;

<<< obj1.val , "original object">>>;
<<< obj2.val , "reference to original">>>;

fun void testclasspassing(test i)
{
    <<< i.val, "in function" >>>;
}

testclasspassing(obj1);
testclasspassing(obj2);


More information about the chuck-users mailing list