4 ms·
Fortran (and previously FORTRAN) passes by value-return, not by reference, even if Unix f77 and VAX Fortran implemented it that way. If you use f77(1) in the f
by gnufx 5y ago
Fortran (and previously FORTRAN) passes by value-return, not by reference, even if Unix f77 and VAX Fortran implemented it that way.
If you use f77(1) in the form of f2c, which I don't have to hand, I changing the value of 1 won't work these days (at least with GCC). It will give a SEGV, because you can expect the C compiler to put constants in read-only storage.
- anonymousiam 5y agoCould you please explain the difference between passing by reference and "value-return"? My understanding is that one can pass by value or by reference. I do not think there is a third alternative. (There are variations on the two in different languages, but I believe there are still only two.) Passing by value creates a copy of the argument and passes the copy. The subroutine/function can modify the copy, but this has no effect on the original argument. Passing by reference is essentially passing a pointer to the object being passed, so if the subroutine/function modifies the object being pointed to, the original value is modified. The latter is what FORTRAN does. MMUs with protected memory, CDS, and no-execute flags are all relatively new concepts that appeared after FORTRAN was created. It's nice that f2c/gcc fixes some of these problems.
- gnufx 5y agoArgument passing is, or was, defined in the "argument association" section of the standard, which obviously doesn't preclude implementing by reference. I don't know whether the same language was in the '66 standard. It isn't anything to do with protected memory as far as I know (which is early '60s); I don't know what CDS is. The point of f2c was just to show that what happens with the invalid code depends on the backend code generation with essentially the same frontend. Regarding different sorts of argument passing, ALGOL 60 had call-by-value, -by-reference, and -by-name.
- anonymousiam 5y agoCDS = code/data separation.