Fortran vs. C (was Re: Ken & Klaus.)
beliavsky_at_aol.com
Date: 09/18/04
- Next message: Nerith Runab: "Can isolation break entanglement?"
- Previous message: Eugene Shubert: "Re: A Challenge for the Experts"
- In reply to: nessuno: "Re: Ken & Klaus."
- Next in thread: nessuno: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Reply: nessuno: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Maybe reply: Linønut: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Maybe reply: Linønut: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Maybe reply: Linønut: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Maybe reply: Linønut: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Maybe reply: Linønut: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Maybe reply: Linønut: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Maybe reply: Shmuel (Seymour J.) Metz: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Messages sorted by: [ date ] [ thread ]
Date: 18 Sep 2004 10:38:05 -0700
nessuno@wigner.berkeley.edu (nessuno) wrote in message news:<f76c1166.0409170717.6ebe4e11@posting.google.com>...
> Robert Newson <ReapNewsB@bullet3.fsnet.oc.ku> wrote in message news:<414ABB87.7070100@bullet3.fsnet.oc.ku>...
> > Jeff Relf wrote:
> >
>
> <snip>
>
> I did a lot of Fortran programming, most of it Fortran 66 (!). The
> older Fortrans were pretty awful by today's standards of what a
> programming language should be. One problem in upgrading them was
> that you had to introduce incompatibilities with previous versions to
> change some things. For example, on going from Fortran 66 to Fortran
> 77, loop testing was moved to the start of the loop (in old Fortran,
> all loops would execute at least once, unless you explicitly put in a
> test to branch around them). I never learned Fortran 95, by then I
> had switched to C. But it was obvious that in order to improve
> Fortran 77, one would have to introduce further incompatibilities with
> it.
What seems "obvious" to you is incorrect in this case. Fortran 90
greatly improved on Fortran 77 and maintained full backward
compatibility. Every standard-conforming Fortran 77 program is an F90
program, with the same meaning.
> Once you've crossed this threshold, the question is, how far do
> you go? If you're willing to go far enough in introducing
> incompatibilities, you could transform Fortan exactly into C, maybe in
> several steps if you wanted to do that. To me it seemed pointless.
> Why not just use C?
Because C is missing a lot of Fortran 95 features:
(1) In Fortran 95, you can allocate a 3-D array with just
real, allocatable :: x(:,:,:)
allocate (x(n1,n2,n3))
The correspoding C code is longer and trickier.
(2) Passing arrays to functions is easier, since their size can
queried. In Fortran you can just write
call foo(x)
and start subroutine foo with
subroutine foo(x)
real, intent(in) :: x(:,:,:)
integer :: n1,n2,n3
n1 = size(x,1)
n2 = size(x,2)
n3 = size(x,3)
It's not easy to write a C function taking a general 2-D or 3-D array
AFAIK.
(3) Fortran 90/95 has array operations and array sections comparable
to Matlab, letting you write fewer lines of code which better reflect
the operations you are trying to perform.
(4) When you do need loops, the Fortran DO-loop is safer than the for
loop of C because you are guaranteed that the loop variable does not
change within the loop. Usually this is what I want. If not, a
DO-ENDDO loop without a loop variable but with an EXIT suffices.
(5) Until C99, which is not so widely used as C90, there are no
complex variables in C.
- Next message: Nerith Runab: "Can isolation break entanglement?"
- Previous message: Eugene Shubert: "Re: A Challenge for the Experts"
- In reply to: nessuno: "Re: Ken & Klaus."
- Next in thread: nessuno: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Reply: nessuno: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Maybe reply: Linønut: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Maybe reply: Linønut: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Maybe reply: Linønut: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Maybe reply: Linønut: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Maybe reply: Linønut: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Maybe reply: Linønut: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Maybe reply: Shmuel (Seymour J.) Metz: "Re: Fortran vs. C (was Re: Ken & Klaus.)"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|