This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Question
- From: Bud Davis <bdavis at f77 dot linksysnet dot com>
- To: fortran at sources dot redhat dot com
- Cc: jfrodrig at unizar dot es
- Date: Mon, 2 Feb 2004 17:58:09 -0600
- Subject: 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