This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Calling FORTRAN from C
- To: Oleg Krivosheev <kriol at bpmail dot fnal dot gov>
- Subject: Re: Calling FORTRAN from C
- From: Toon Moene <toon at moene dot indiv dot nluug dot nl>
- Date: Mon, 04 Dec 2000 19:50:48 +0100
- CC: Robert Boehne <rboehne at ricardo-us dot com>,Robert Kuhn <Robert_Kuhn at mgic dot com>, gcc at gcc dot gnu dot org
- Organization: Moene Computational Physics, Maartensdijk, The Netherlands
- References: <Pine.GSO.4.20.0012041153460.10108-100000@boopsie.fnal.gov>
Oleg Krivosheev wrote:
[ ... How to link Fortran and C ... ]
> i believe it is offtopic for gcc @gcc.gnu.org, so we'd better move the
> discussion to private e-mail
Sure, but:
> Robert, feel free to ask how to link Fortran and C, there are some
> tricks involved in COMMON linkage and string arguments.
I thought this was all covered in the g77 manual ?
BTW, to answer the original question Robert Kuhn posed:
No, it is *not* necessary to use a C routine (or main program) to have
variable length arrays.
If you just want to have arrays that match a certain "problem size", you
could proceed as follows:
READ*, N,L,M
CALL MAIN(N,L,M)
END
SUBROUTINE MAIN(N,L,M)
DIMENSION A(N,L,M), B(N,L,M), C(N,L), D(L,M) ! ... etc
... compute ...
END
This is completely valid Fortran 9x (and compiled correctly by g77).
The only catch is that the arrays in SUBROUTINE MAIN are allocated on
the stack by g77 and most OS's do not allow you a lot of stack space (on
GNU/Linux this typically is 8 Mbyte).
The cure to this problem is to have a file /etc/initscript with:
ulimit -s 65536
in it (or more if you want more than 64 Mbyte of stack). See `man
initscript'
_Now_ it's getting off-topic, so I'll quit :-)
--
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
GNU Fortran 95: http://g95.sourceforge.net/ (under construction)