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.
.



Relevant Pages

  • Re: recurse subdirectories without using File::Find
    ... Why are you ignoring a known non-buggy solution in favor of ... You start by writing better code, and asking Perl for help whenever you ... Why are you calling the subroutine with the & on front? ...
    (perl.beginners)
  • Re: writing drivers using C++
    ... You are trying to sidestep the issue by writing about something ... coding against an interface - when the implementation starts mattering to ... Every subroutine invokation has to be coded manually, ...
    (comp.os.linux.development.system)
  • Re: Function questions?
    ... it isn't obvious what the subroutine ... call compute_f (x, args) ... With many levels of nested calls, debugging by writing out intermediate results becomes impossible. ... I always declare functions using RESULT and no prefix ...
    (comp.lang.fortran)
  • Re: [QUIZ][SOLUTION] Kalah (#58)
    ... preceding URL makes it look harder and more cumbersome than just writing a ... subroutine to exercise your new class. ...
    (comp.lang.ruby)
  • Re: solving an equation multiple directions
    ... On Fri, 16 Jan 2009, Jason wrote: ... writing the equation twice. ... but without writing two equations to prevent duplication in my code. ... Perhaps you want a subroutine. ...
    (sci.math)