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: use go to doing some case studies and induced problems
    ... these case studies are not so worthy of writing them as ... If for some reason I really didn't want a separate routine with an argument list, I'd use an internal subroutine. ... Anything so short that it's not worth making a subroutine for, I'd put inline in the code. ... I'd have to say, this sounds like it could easily lead to GIGO (garbage in, garbage out) when you miss something in the logic. ...
    (comp.lang.fortran)