Re: Basic question on local variable



glen herrmannsfeldt wrote:
Led wrote:
For a subroutine I can understand, but for a function
I don't see the point. Again, that must be my MATLAB
influence that blinds me.

I do wonder what fraction of Fortran functions modify
any of their arguments. It is fairly common in C, if you
count passing a pointer to a variable.

Right, but in C, there is no such thing as a subroutine as distinct from a function, so such things are to be expected -- given that subroutines are certainly useful, and there's no other way to do them.

In Fortran, where I have the luxury of writing my subroutines as subroutines and my functions as functions rather than having to have them all forced into the same mold, I almost never I write functions where the arguments are anything other than INTENT(IN).

(I could perhaps see some use in the C-ism of writing a subroutine as a function that returns a boolean success code, but in Fortran that seems unnatural to me, so in practice I don't do it; either the subroutine does its own die-on-error handling, or the success flag is an ordinary argument.)

- Brooks


--
The "bmoses-nospam" address is valid; no unmunging needed.
.