4 ms·
Not the author, but I'll have a shot: I think the problem is with responsibility for memory allocation and freeing. To dispose of a nested array's memory, you
by theoh 10y ago
Not the author, but I'll have a shot: I think the problem is with responsibility for memory allocation and freeing.
To dispose of a nested array's memory, you would need to follow all of its pointers to an arbitrary depth, or, alternatively, keep track of every reference in the program (and garbage collect "dead" arrays).
Arrays can't be returned from a function if they're allocated on the heap, or to put it more abstractly, if you returned an array you would lose the ability to straighforwardly limit its lifetime by tying it to the function's scope.
(Conventionally, functions free all their "local" storage on returning.)
So, in the absence of both manual memory management (e.g. malloc and free) and garbage collection, you can't allow an array to be returned from a function, or cope with nested arrays without special support from the language.