Date: Tue, 22 Jul 1997 12:36:24 -0400 (EDT) From: "Art S. Kagel" To: "John M. Wildenthal" Cc: djgpp AT delorie DOT com Subject: Re: Calling Fortran subroutines? In-Reply-To: <33CFABEE.DAEBDD9D@tamu.edu> Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Fri, 18 Jul 1997, John M. Wildenthal wrote: > I am trying to see if I must use F2C on Fortran77 code, or can I just > compile it (using G77) and treat it as just another set of object code? > > I have been told that C and Fortran pass arguments in different order > (LIFO vs FIFO), but I was wondering if arrays were passed by address > (like C) or value. No, FORTRAN and C push arguments in the same order. The difference is that C treats all arguments as pass by value while FORTRAN passes by reference. Pass by reference is equivalent, in C, to always passing a pointer to every variable. Also FORTRAN does not use NULL terminated strings and contains language level string support so any CHARACTER type argument also passes a hidden INTEGER*4 argument containing the length of the string. Different FORTRANs pass this differently: some immediately following the associated string, some with all of the length parameters ganged up at the end of the argument list. I don't know what GCC does. It should be documented. The answer to your latter question is that arrays are passed by address in FORTRAN like in C but so are all other argument types. You can call C from FORTRAN and FORTRAN from C. FORTRAN usually shifts all names to lower case to and appends an underscore to global object names like subroutines and common blocks. Treat named common blocks as extern structures. Just declare a struct/typedef to match the common's definition in FORTRAN. Call all FORTRAN SUBROUTINES as C functions returning void with pointers for arguments in the same order as FORTRAN. Similarly to access C from FORTRAN make sure that the function name ends in an underscore and that all arguments are pointers. If the function returns a simple type you can call it as a FORTRAN function otherwise as a subroutine. C global variables similarly must be named in lower case with the trailing underscore and can be declared in FORTRAN as a named common with the underscore stripped. Art S. Kagel, kagel AT bloomberg DOT com