This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Calling FORTRAN from C


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)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]