Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Pass by reference

    Advanced
    6
    9
    782
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Hazematman
      Hazematman F last edited by

      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.

      1 Reply Last reply Reply Quote 3
      • Discostew
        Discostew F last edited by

        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.

        1 Reply Last reply Reply Quote 1
        • N
          Nisse5 F last edited by

          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?

          1 Reply Last reply Reply Quote 1
          • M
            MikeDX last edited by

            some values are already passed by reference (confusing i know)

            this all needs to be cleaned up and documented properly

            Discostew 1 Reply Last reply Reply Quote 3
            • Discostew
              Discostew F @MikeDX last edited by

              @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?

              M 1 Reply Last reply Reply Quote 2
              • M
                MikeDX @Discostew last edited by MikeDX

                @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)

                1 Reply Last reply Reply Quote 1
                • Eearslya
                  Eearslya Donator last edited by

                  I know for a fact I ran into pass-by-reference accidentally when doing new_array = old_array. Modifying elements of new_array ended up modifying the same elements in old_array. That's the only example I've seen so far.

                  Discostew ITzTravelInTime 2 Replies Last reply Reply Quote 2
                  • Discostew
                    Discostew F @Eearslya last edited by

                    @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.

                    1 Reply Last reply Reply Quote 1
                    • ITzTravelInTime
                      ITzTravelInTime F @Eearslya last edited by

                      @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

                      1 Reply Last reply Reply Quote 1
                      • First post
                        Last post