3 ms·
fortran is call by reference, it's all aliasing, you can even in some implementations change the value of literals c is call by value, you have to at least try
by fsckboy 3y ago
fortran is call by reference, it's all aliasing, you can even in some implementations change the value of literals
c is call by value, you have to at least try to alias
- gpderetta 3y agomy understanding is that in fortran, if two arguments alias each other, it is UB. So it is not that fortran doesn't have aliasing, it is just that the optimizer assume that it doesn't (but don't quote me on this!).
- Bostonian 3y agoArguments are allowed to alias if they are both inputs that will not be changed in the function -- technically if they are both "intent(in)".
- pklausler 3y agoINTENT(IN) is not required to allow aliasing of unmodified dummy arguments.
- kergonath 3y agoYes, but in practice no compiler checks whether an argument with no INTENT is modified or not, or could alias with something else or not. So the compilers tend to trust the programmer. With INTENTS, it’s obvious and much easier to check.
- pklausler 3y agoDummy argument aliasing has nothing to do with INTENT.
- TheRealKing 3y agoI believe the NAG Fortran compiler does check for some aliasing scenarios if not all. The argument intent is irrelevant.
- gnufx 3y agoFortran does not call by reference, and the term aliasing isn't used by the standard. It calls by what's usually called value-return or copy-in/copy-out, according to the "storage association" rules in the standard. While it may be true that the rules aren't generally checked by compilers, Toolpack did it for pure Fortran77 in the 1980s, though I don't know how comprehensive it actually was.
- bregma 3y agoIt took me days one time to figure out why 0 had adopted the value four. The technicality is that Fortran is call by descriptor (not by reference, not by value). That's a powerful difference but a sharp two-edged sword.
- kaba0 3y agoCould you please explain how is it differs from the other two? Never looked into Fortran.
- kergonath 3y agoThe Fortran standard does not specify anything about passing by references or value. Instead, it specifies the expected results. The compilers do it however they want or can, which means that they can pass pointers, values, copies, or pointers to copies depending on the situation. Sometimes (most of the time, to be fair), the compiler can work out the best solution. Sometimes, the developer has to jump through some hoops to avoid unnecessary copies.