6 ms·
fortran - one of only a handful of languages that natively supports multidimensional arrays, maybe the only low level one?
by dm319 6y ago
fortran - one of only a handful of languages that natively supports multidimensional arrays, maybe the only low level one?
- ironmagma 6y agoC kind of does, right? A multidimensional array in C isn't just an array of pointers.
- dm319 6y agoIs that more of a jagged / ragged array, or array of arrays? Sometimes these are called multidimensional arrays, but these are not the same thing. Dimensions and lengths of the dimensions should be a property of the multidimensional object. [1] https://stackoverflow.com/questions/597720/what-are-the-differences-between-a-multidimensional-array-and-an-array-of-arrays https://stackoverflow.com/questions/597720/what-are-the-diff...
- ironmagma 6y agoI was talking about int a[2][3]; in C. Is that jagged? I wouldn’t have thought so, since AFAIK you could only store 6 elements in that and no fewer. Interestingly you cannot take the value of &&a[0][0], assign it to an int **b; pointer b, and then access it via b[0][0] because it’s stored as a contiguous block of integers rather than an array of pointers that point to arrays as you might expect.
- dm319 6y agoYes, that's a jagged/ragged/array-of-array, and most languages support them. There isn't a requirement for the arrays to be the same length. There are many arguments about the pros and cons of each, and how different they are the closer to assembly you get. Golang had a proposition to include multidimensional arrays [1], there were lots of arguments. I think the different perspectives depend on what you want to use it for and how much numerical processing you do. [1] https://github.com/golang/go/issues/6282 https://github.com/golang/go/issues/6282
- ironmagma 6y agoAccording to this thread, it is not a true jagged array because each row has the same number of columns and each column the same number of rows. You can initialize it as a jagged array but it will still allocate it like a matrix. https://stackoverflow.com/questions/1083658/do-jagged-arrays-exist-in-c-c https://stackoverflow.com/questions/1083658/do-jagged-arrays... > the array will still have the shape [2][3]. If you want a true jagged array, you will have to create it dynamically.
- dm319 6y agoAh ok, I was discriminating between a true multidimensional array and array-of-array (which can be ragged).
- CyberDildonics 6y agoThat's ridiculous, you can make a C++ class and overload operator() like Eigen to easily make a multi-dimensional array.
- baggy_trough 6y ago"natively"
- CyberDildonics 6y agoWhat is different to fortran's multi-dimensional arrays? The interface can be almost identical and the memory layout in C++ can be whatever you want it to be.
- enriquto 6y agoBy that reasoning, all turing-complete languages support multi-dimensional arrays.
- CyberDildonics 6y agoI don't think every turing complete language lets you create an interface and memory layout that would be identical to fortran.
- cjhanks 6y agoJulia, R, and MATLAB. But yeah, it's not common. I end up reinventing this wheel about once a year.
- Someone 6y agoPlankalkül (https://en.wikipedia.org/wiki/Plankalkül https://en.wikipedia.org/wiki/Plankalkül), Superplan (https://en.wikipedia.org/wiki/Superplan; https://en.wikipedia.org/wiki/Superplan; never implemented) Pascal, Modula, Oberon, COBOL, ALGOL 60, dBase, Visual Basic (not all ‘low-level’) (and probably many others)
- BitterAmethyst 6y agoNot a low-level one but the CLR natively supports multidimensional arrays although I don't think they are exposed to C#. I've written some F# code and for some trivial cases I was benchmarking there was some interesting performance differences between a native multi-dimensional array and an array-of-arrays version. It wasn't important enough to look into so I don't know if the difference is due to quirks of the CLRs implementation or due to memory access patterns.