On Mon, 11 Feb 2013 07:52:28 +0100 "deadalnix" <[email protected]> wrote:I'm thinking about it for a while now and I'm now convinced that we should allow the compiler to do that job for us. Let me explain.To be honest, up until recently, I mistakenly thought the compiler DID do this. (Yea, my mistake.)Is it possible I had confused structs with static arrays? Do static arrays do that?
I'm pretty sure static/fixed arrays are more like structs, and thereby whole copies are made rather than sending a slice. Let's find out.
void main() {
char[4] test = "test";
writeln(&test, "- main");
fun(test);
if (test == "test")
writeln("is passed by value/copy");
else {
assert(test == "best", "Something's wrong...");
writeln("is passed by slice/ref");
}
}
void fun(char[4] test){
assert(test == "test");
writeln(&test, "- fun");
test[0] = 'b';
assert(test == "best");
}
Output:
18FDD0- main
18FDAC- fun
is passed by value/copy
