This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Question


To call C routines from fortran:

The C routines name  must be  all lower case and must end in an underscore.  

If the C routine name has an underscore in it, then the name must end in two underscores.

Use "CALL <c_routine_name>" in fortran, without the trailing underscore(s).
Upper / Lower case does not matter in fortran.

Here is a little example that works with redhat 9:

$ cat fmain.f
       I = 1
       PRINT*,'Before the C routine',I
       CALL CROUTINE(I)
       PRINT*,'After the C routine ',I
       END
 
$ cat croutine.c
void croutine_( int *a)
// Note the name: all lowercase and with an underscore
{
           *a = *a + 1;
           return;
}
$ g77 fmain.f croutine.c
$ ./a.out
 Before the C routine 1
 After the C routine  2


Hope this helps,
bud davis


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