5 ms·
Could 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
by anonymousiam 5y ago
Could 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.