Path: utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hpda!hpdslab!hp-ptp!mlight From: mlight@hp-ptp.HP.COM (Mike_Light) Newsgroups: comp.sys.hp Subject: Re: C calls to Fortran subroutines on HP9000/300 Message-ID: <1320002@hp-ptp.HP.COM> Date: 25 May 89 15:38:45 GMT References: <436a0d6e.d498@mets.engin.umich.edu> Organization: HP Pacific Technology Park - Sunnyvale, Ca. Lines: 34 >I am trying to call Fortran subroutines from a C main >program, but don't know how to set up the call. I can't find >any preprocessor commands like ALIAS which you can use when calling >C from a Fortran program. C assumes the caller knows what he is doing when invoking a function. It is up to the programmer to know the interface the called function expects. Fortran has a simple call-convention unless you need to share strings. Most normal data types in fortran are passed by reference, i.e., fortran routines expect to be given a pointer to the integer, real, or complex number. Doing this from a C caller is as simple as: int arg1, arg2 ... ; fortran_func(&arg1, &arg2, ...); Strings are beasts from hell and you don't want to use them between languages because they are manipulated in very different ways. But if you must, be warned that fortran expects TWO parameters when a string parameter occurs; the first parameter is a pointer to the string, and the second is the length of the string PASSED BY VALUE! Fortran would also expect the string to be blank-padded on the right out to the string length. char f_string[80]; sprintf(f_string,"%80s","String Data"); fortran_str(f_string,80); Enjoy! ----------------------------------------------------------------------- Mike Light HP Industrial Applications Center - mlight@hpiacla.HP.COM -----------------------------------------------------------------------