@neauoire You can pass a pointer to an array!

I'm no C programmer though, don't know how good of an idea this is

@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 I'm sure C can withstand any attack I wage against its name 😁 As can JavaScript, albeit in a different way

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

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

@cancel @neauoire If all the struct contains is an array then there's no difference from the point of view of the computer and the developer. Like the only difference here is semantic.

@alexandria_ @neauoire if a struct contains an array and you return that struct, you are still returning a struct, not an array. arrays are not values in C.

@cancel @neauoire It's like saying you can't use an int as a boolean because it can contain larger values than just 0 and 1. Ok semantically you're right, but nobody really cares and the computer is literally none the wiser anyway.

@alexandria_ @neauoire I don't understand what you are trying to tell me. I said you cannot return arrays in C. You showed an example of returning a struct. I don't understand.

@cancel @neauoire This discussion is literally equivalent to:

`Ok we have xyz:
int xyz = 0;
which is a boolean`

`That's not a boolean that's an integer`

`We're using it as a boolean, for all intents and purposes that's a boolean`

`Yeah but it's not a boolean`

@alexandria_ I was talking about language features. I don't know what you think I was saying.

@cancel @neauoire Like the only space allocated on the caller's stack is the space of the array. The only way it accesses it is as an array. The assembly listing doesn't care that it's a struct. It doesn't even know that it is a struct. This is pure pedantry.

@alexandria_ @neauoire I don't know what kind of strange problem you have with me. You must be imagining that I said something that I didn't actually say?

Sign in to participate in the conversation

Merveilles is a community project aimed at the establishment of new ways of speaking, seeing and organizing information — A culture that seeks augmentation through the arts of engineering and design. A warm welcome to any like-minded people who feel these ideals resonate with them.