| ▲ | adrian_b 4 days ago | |
There is a language enforced difference. Fortran functions correspond to "pure" functions in C/C++ and other languages, i.e. idempotent functions that do not modify arguments or global variables. If a C/C++ function is converted to Fortran, it must be rewritten as a subroutine, unless it is a pure function. Not all C/C++ compilers support the language extension of marking functions as pure, and even with such compilers many programmers are lazy, so they forget to mark as pure the functions where this is applicable, even if this is recommended for improving program optimization and verification. Fortran function were pure functions because this is the mathematical sense of the term "function". The extension of the meaning of the word "function" for any kind of procedure happened decades after the creation of Fortran. The distinction between a "void" function and other functions has negligible importance. On the other hand the distinction between "functions" in the C language sense and "pure functions" is very important and programmers should better mark as "pure" all the functions for which this is true. This is at least as important for program optimization and for checking program correctness as declaring a variable with the correct type. | ||
| ▲ | pklausler 4 days ago | parent [-] | |
> Fortran functions correspond to "pure" functions in C/C++ and other languages, i.e. idempotent functions that do not modify arguments or global variables. This is nonsense. Fortran functions aren't pure. They can have side effects. HPF/Fortran '95 added the PURE attribute for subprograms, but it's not the default. | ||