@neauoire you can put the relevant array-related information in a struct and return that
just as long as you remember to clean up afterwards
@neauoire This is like learning your judgey aunt is incontinent
@neauoire This seems very similar to how I felt when I went from python to C++ :D
Btw if you ever need _another_ person to ask about C, I'm happy to help.
@tmpvoid cheers :)
@neauoire I mean you don't really return an array in JS you are REALLY(almost always) returning a reference. Hence == vs ===. One is reference equality the other value.
@neauoire working with unsized types in general is hard or impossible (you typically don't statically know the length of a vector, which is what I assume you mean by array i.e. js array)
in interpreted languages you're usually operating on some sort of opaque reference
and in compiled languages that have some way to implicitly "return" collections of that sort it's typically a fixed-size wrapper structure that manages heap memory (i.e. some pointers) containing the actual data
@neauoire you kinda can, actually. You just have to understand that a C array is actually just a pointer to a blob of memory somewhere, and you have to understand where exactly that memory lives. If you created it on the stack and pass a reference to it back up the stack (it grows down; yes this is confusing), your reference is as meaningless as that old stack frame—but if you created it on-heap or it came up-stack from you, it IS a reference to something meaningful that you can pass around as you see fit
@nfd @neauoire important to this is the fact that the return address is passed on the stack. So the stack pointer has to be pointing at the part of memory where that address is otherwise the computer doesn't know where to go.
Now this doesn't preclude you from putting something on the stack, shifting the stack pointer back to the return address, and then letting the caller figure out where and how big the thing you're passing is.
@nfd @neauoire But back in i386 you had limited registers (six normal plus four segment registers plus some random bookeeping ones), it was common to use the stack to store variable data too (and gcc still does this by default if you don't ask it to optimize), so that isn't done. Also you would have to adjust the stack pointer before calling any other functions otherwise it would clobber the data you have in the stack, and you would have to clean all that off afterwards. Messy!
@neauoire Yes you can.
@neauoire You can wrap it as a struct and have the value passed straight out of the function but everyone uses pointers passed to the functions for Reasons
@neauoire dw I muted em
@alexandria_ I was talking about language features. I don't know what you think I was saying.
Revel in the marvels of the universe. We are a collective of forward-thinking individuals who strive to better ourselves and our surroundings through constant creation. We express ourselves through music, art, games, and writing. We also put great value in play. A warm welcome to any like-minded people who feel these ideals resonate with them. Check out our Patreon to see our donations.