Re: double confusion
- From: Ian Bush <I.J.Bush@xxxxxxxxxxxxxxx>
- Date: Mon, 17 Jul 2006 14:47:53 +0000
Julian Bessenroth wrote:
Ian Bush schrieb:
How is it different from C ?
If the subprogram and the main program were in different files and
compiled separately how could you ensure that the main program knows what
return type the function has ?
But these declaration are located onlz _once_ at the begining of the
file (before the main routine starts).
That just reflects the scoping rules in the language - C has a concept of file
scope, while Fortran has different rules. In particular you should look into
Modules that came in in Fortran 90, where you can just declare things "once at
the beginning"
Fortran requires its
declarations "within the main routine" and within every
subroutine/function where i'm going to use the this function, and what
confuses me somewhat more, that it's just required for double
precision, but not for integer or real ...
This reflects the implicit Typing of the languages - in C functions return
int by default so one could argue that it only applies to functions returning
other types. Let's take a look at your example:
program bcont
double precision c
double precision a /2.0/
double precision b /2.0/
c=r(a,b)
write(*,*) 'result = ',c
stop
end
double precision function r(m,t)
double precision m
double precision t
r = m*t
c write(*,*) 'm = ',m,' t = ',t,' m*t= ',r
return
end
By default in fortran love it or loath it variables and functions
beginning with a-h and o-z are real, while i-n is integer. So "god"
is real, but not complex or logical. If you want something that is
not real or integer you have to declare it ( or ... no I won't go there ).
Thus you must declare all double precision variables. In fact many people
think using the implicit typing scheme is bad practice, or at the very least
leaves your code more susceptible to bugs due to typos, and so many people would
use "Implicit None" which forces you to declare all your variables. Having to
declare all the variables that are in scope ? Is that really that much different
from many other languages ?
BTW as hinted above you seem to be using Fortran 77, which is 3 standard revisions
out of date. I would suggest if you want to start using Fortran again you look
into Fortran 90 & 95, I would suggest the latest standard but there aren't any full
compilers out for it yet,
Ian
.
- Follow-Ups:
- Re: double confusion
- From: Richard Maine
- Re: double confusion
- References:
- double confusion
- From: Julian Bessenroth
- Re: double confusion
- From: michael
- Re: double confusion
- From: Julian Bessenroth
- Re: double confusion
- From: Ian Bush
- Re: double confusion
- From: Julian Bessenroth
- double confusion
- Prev by Date: Re: writing output listing onto screen (or not) and onto file
- Next by Date: Re: I/O reading formated files
- Previous by thread: Re: double confusion
- Next by thread: Re: double confusion
- Index(es):
Relevant Pages
|