Pass by reference
-
Is there anyway to pass a reference of struct or an array to a function? It looks like when you call a function with a variable it always makes a copy. Supporting this would make it easier to write clean code that doesn't depend on global state.
-
Would love it. I just now had to alter my code a bit because some large arrays are stored within structures within structures, and having to pass the structures by value would have to copy those large arrays each time. Now these large arrays are closer to the root structure and the nested structures reference them with a value instead.
-
I don't think there's a way, but I surely would want it. Code dealing with arrays, structs and vectors could become so much cleaner (and resource-friendly) with it. Don't know if it's already in the wish list thread - if not, perhaps you could add a request there?
-
some values are already passed by reference (confusing i know)
this all needs to be cleaned up and documented properly
-
@MikeDX said in Pass by reference:
some values are already passed by reference (confusing i know)
this all needs to be cleaned up and documented properly
Might we inquire as to what values in particular?
-
@Discostew said in Pass by reference:
Might we inquire as to what values in particular?
Someone with more knowledge than me will have to answer that I'm afraid (hence the cleanup/document comment)
-
I know for a fact I ran into pass-by-reference accidentally when doing
new_array = old_array
. Modifying elements ofnew_array
ended up modifying the same elements inold_array
. That's the only example I've seen so far. -
@Eearslya Been doing a few tests, and it would seem that structures also follow the pass-by-reference rule. Strings as-is don't seem to.
-
@Eearslya The same happened with structures, but changing an element of the new one sometimes results into a dupicate being made https://fuzearena.com/forum/topic/381/duplicating-structs