3 ms·
I thought that the specific issue was that arrays could only directly contain strings of equal length. Which, yeah, that's necessary in order for array access t
by mumblemumble 5y ago
I thought that the specific issue was that arrays could only directly contain strings of equal length. Which, yeah, that's necessary in order for array access to be O(1) and for any sorts of vector intrinsics or striding operations to work properly.
The way to get around that is by sticking the actual string on the heap somewhere and only storing a pointer to it in the array. This isn't a unique problem to Fortran; it's how basically every programming language does it. The difference is that Fortan doesn't automatically heap allocate them for you - you've got to manually box them with a derived type - and that most other languages don't even give you the option of strings without pointer chasing.
I would argue that, while this characteristic is certainly going to seem weird to anyone who's used to a higher-level language, in a language like Fortran where the primary use case is high performance computing, putting the programmer in charge of these sorts of decisions is neither a bug nor a wart; it's a huge feature.
- terminalcommand 5y agoI agree, this makes sense, having O(1) access to all items in a string array seems logical to me, you would also avoid problems with forgetting \n termination like in C.
- mumblemumble 5y agoThough it does create its own separate class of potential bugs. When you assign some text to a fixed-length string, Fortran will silently truncate or space-pad it to make it the correct length.